1

I have a Json string

"[{'SymptID': '" + MidID + "', 'ALvl' : '" +JawLvl + "'},
{'SymptID': '" + BckID + "', 'ALvl' : '" + PanLvl + "'},
{'SymptID': '" + SysID + "', 'ALvl' : '" + wPLvl + "'}]"

 

Dictionary<string, string> Symptoms =
    (Dictionary<string, string>)Newtonsoft.Json.JsonConvert.DeserializeObject(
        data, typeof(Dictionary<string, string>));

foreach (KeyValuePair<string, string> keyValuePair in Symptoms)
{ //do some action }

how can make this get keys and values with this multiple array json data... is there any other methods.

NOTE:The question is not a duplicate to How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?, because json structure is different.

Here we have an array of objects with 2 properties SymptID and ALvl, that need to be converted to dictionary with key SymptID and value ALvl.  Referred question has one object with multiple properties having corresponding values that needs to be converted to dictionary with property name as key  and property value as value in dictionary.

Community
  • 1
  • 1
deepu
  • 1,993
  • 6
  • 42
  • 64
  • you can alternatively use the JavaScriptSerializer class (System.Web.Extensions). var result = serializer.Deserialize>(yourJsonString); – Giorgio Minardi Dec 16 '11 at 15:41

1 Answers1

0

you can also use json.net or fastjson opensource libraries to perform this task in a faster and efficient way than using the built in .net serializer.

json.net - http://json.codeplex.com/

fastJson - http://www.codeproject.com/Articles/159450/fastJSON

Ademar
  • 5,657
  • 1
  • 17
  • 23