Convert string to Json Array

我的梦境 提交于 2019-12-24 12:35:03

问题


I have a Dictionary like that:

Dictionary<string, string> // key value pair

and the example values are:

Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("key1","value1");
parameters.Add("products","[{"name":"Widget A","qty":3},{"name":"Widget B","qty":1}]");

how Can I serialize that as :

vars={"key1":"value1",products":[{"name":"Widget A","qty":3},{"name":"Widget B","qty":1}]} 

When I try to serialize :

vars={"key1":"value1",products":**"**[{"name":"Widget A","qty":3},{"name":"Widget B","qty":1}]**"**} 

its append double quotes. Using JSON.Net

I'm using third party API and it accepts HashTable for parameters.

thanks


回答1:


Define Dictionary object as

Dictionary<string, object>

instead of

Dictionary<string, string>.



来源:https://stackoverflow.com/questions/14935677/convert-string-to-json-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!