我有一个字典,其中一个值是另一个字典。我一直在使用NameValueCollection
和WebClient
将字典转换为用于发布的URL。
我现在遇到的问题是如何转换这个字典,以便正确创建url。
这里有一个json版本的字典:
{
"One" : "Hello",
"Two" : "World",
"Three" : {"Sub-One" : "This is an embedded dictionary"}
}
这是我想要得到的url字符串:
myUrl.com?One=Hello&Two=World&Three[Sub-One]=This%20is%20an%20embedded%20dictionary
有图书馆或实用程序吗?
您可以查看ServiceStack的JSV格式:https://github.com/ServiceStackV3/mythz_blog/blob/master/pages/176.md在ServiceStack.Text nuget包中可用,因为这应该可以满足您的需要。
唯一的区别是它将在键和值之间使用JSON样式":"而不是"=",例如
{One:Hello,Two:World:Three:[{Sub-One:This is....}]}
但是用作查询字符串是安全的。