【发布时间】:2019-06-26 18:46:08
【问题描述】:
所以我使用 Newtonsoft.Json 发送 POST 请求。
我必须使用字典来指定我的键和值。
这是 POST 在接收端的样子:
{"type":"direct","packages":["http://whatever:9999/something.pkg"]}
我的代码:
dictData.Add("type", "direct")
dictData.Add("packages", "[http://whatever:9999/something.pkg]")
jsonPost.postData(dictData)
还有输出:
{
"type": "direct",
"packages": "[http://whatever:9999/something.pkg]"
}
所以问题是:我不希望有空格,我希望所有内容都在一行中,并且我希望 URL 用引号引起来。我尝试了双“”方法,得到了我的引号,但它还在 URL 的开头和结尾放置了一个 \。
我确信这很简单,但在我的一生中,我找不到任何有用的东西。
【问题讨论】:
-
尝试将包值作为数组或字符串列表而不是标量字符串传递,例如
dictData.Add("packages", {"http://whatever:9999/something.pkg"})。括号的位置表明它应该被视为一个列表(只有一个成员)而不是一个标量。
标签: json string vb.net dictionary post