Array:
{
"field':["field1":"value1","field2":"value2"],
["field1":"value1","field2":"value2"]
}
How to parse the above json response in c#
the json
string you provided is not correct in json
format, the json
array should be:
{"field":[
{"field1":"value1","field2":"value2"},
{"field1":"value1","field2":"value2"}
]
}
You can use json.net
to convert it:
var obj = JsonConvert.DeserializeObject(json);
This tool is also available in nuget.
If you want to use strong type:
public class YourObject
{
public string Field1 { get; set; }
public string Field2 { get; set; }
}
public class YourClass
{
public YourObject[] Field { get; set; }
}
var yourClass = JsonConvert.DeserializeObject<YourClass>(json);
Use newtonsoft json.net for parsing json response.
It is simple and easy
I answered same kind of question here. Take a look at it once
It may be worth taking a look at the javaScriptSerializer Class. and the deserialize method within.
JavaScriptSerializer jss= new JavaScriptSerializer();
User user = jss.Deserialize<User>(jsonResponse);