Reputation: 2375
I have a set of data(key value pair) which I need map to json, note keys are not fixed, name of keys are not fixed. thanks e.g.
How to map
dict<string, list<string>>
{"Module",new List<String>(){"Allprice"}},
{"Code",new List<String>(){"PA0000606", "PA0000669"}},
{"ContinuosForwardPeriod", new List<string>() {"0"} ,
{ "TimeStampID", new List<string>{"0"},
{"PriceTypeID": "8"}
to
[
{ "Module": "Allprice",
"Code": "PA0000606",
"ContinuosForwardPeriod": "0",
"TimeStampID": "0",
"PriceTypeID": "8"
},
{ "Module": "Allprice",
"Code": "PA0000669",
"ContinuosForwardPeriod": "0",
"TimeStampID": "0",
"PriceTypeID": "8"
}
]
Upvotes: 0
Views: 88
Reputation: 18850
using System.Web.Script.Serialization.JavaScriptSerializer;
JavaScriptSerializer oSerializer = new JavaScriptSerializer();
string JSON = oSerializer.Serialize(yourDict);
Upvotes: 1