c# – 有哪些选项可以将网址编码的表单数据转换为.Net中的JSON

c# – 有哪些选项可以将网址编码的表单数据转换为.Net中的JSON,第1张

概述我有一个Web请求发送格式为application / x-www-form-urlencoded的服务器数据.我想把它转换为application / json. 例: 网址编码表单资料: Property1=A&Property2=B&Property3%5B0%5D%5BSubProperty1%5D=a&Property3%5B0%5D%5BSubProperty2%5D=b&Proper 我有一个Web请求发送格式为application / x-www-form-urlencoded的服务器数据.我想把它转换为application / Json.

例:

网址编码表单资料:

Property1=A&Property2=B&Property3%5B0%5D%5BSubProperty1%5D=a&Property3%5B0%5D%5BSubProperty2%5D=b&Property3%5B1%5D%5BSubProperty1%5D=c&Property3%5B1%5D%5BSubProperty2%5D=d

漂亮版本:

Property1=AProperty2=BProperty3[0][SubProperty1]=aProperty3[0][SubProperty2]=bProperty3[1][SubProperty1]=cProperty3[1][SubProperty2]=d

上述数据需要转换为以下JsON数据:

{    Property1: "A",Property2: "B",Property3: [        { SubProperty1: "a",SubProperty2: "b" },{ SubProperty1: "c",SubProperty2: "d" }]}

题:

有没有任何能够做到这一点的免费工具?我没有找到任何自己,如果他们存在,我宁愿消费他们而不是自己写一个,但如果是这样,我会的.

C#/.Net解决方案是首选.

解决方法 我已经编写了一个用于解析查询字符串和表单数据的实用程序类.可在:

https://gist.github.com/peteroupc/5619864

例:

// Example query string from the questionString test="Property1=A&Property2=B&Property3%5B0%5D%5BSubProperty1%5D=a&Property3%5B0%5D%5BSubProperty2%5D=b&Property3%5B1%5D%5BSubProperty1%5D=c&Property3%5B1%5D%5BSubProperty2%5D=d";// Convert the query string to a JsON-frIEndly dictionaryvar o=queryStringHelper.queryStringToDict(test);// Convert the dictionary to a JsON string using the JsON.NET// library <http://Json.codeplex.com/>var Json=JsonConvert.SerializeObject(o);// Output the JsON string to the consoleConsole.Writeline(Json);

让我知道如果它适用于你

总结

以上是内存溢出为你收集整理的c# – 有哪些选项可以将网址编码的表单数据转换为.Net中的JSON全部内容,希望文章能够帮你解决c# – 有哪些选项可以将网址编码的表单数据转换为.Net中的JSON所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1259974.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存