问题
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