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.

1
  • you can alternatively use the JavaScriptSerializer class (System.Web.Extensions). var result = serializer.Deserialize<Dictionary<string, string>>(yourJsonString); Commented Dec 16, 2011 at 15:41

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.