shortcode
shortcode

Reputation: 457

Convert string to Json Array

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

Upvotes: 1

Views: 2497

Answers (1)

Nuri YILMAZ
Nuri YILMAZ

Reputation: 4331

Define Dictionary object as

Dictionary<string, object>

instead of

Dictionary<string, string>.

Upvotes: 1

Related Questions