将字符串转换为Json数组

时间:2013-02-18 11:53:18

标签: json jsonserializer

我有一个类似的词典:

Dictionary<string, string> // key value pair

,示例值为:

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}]");

如何将其序列化为:

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

当我尝试序列化时:

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

附加双引号。使用JSON.Net

我正在使用第三方API,它接受参数的HashTable。

感谢

1 个答案:

答案 0 :(得分:1)

将Dictionary对象定义为

Dictionary<string, object>

而不是

Dictionary<string, string>