I just started dabbling with C#, and I’ve been banging my head over JSON deserialization for a while now. I’m using Newtonsoft.Json library. I’m expecting just a json response of an array of dictionaries as such
[{"id":"669","content":" testing","comments":"","ups":"0","downs":"0"}, {"id":"482","content":" test2","comments":"","ups":"0","downs":"0"}]
Right now I have: (note: download is just a string holding the json string)
string[] arr = JsonConvert.DeserializeObject<string[]>(download);
I’ve tried many different ways of doing this, each failed. Is there a standard way for parsing json of this type?
You have an array of objects not strings. Create a class that maps the properties and deserialize into that,
There are only a few basic types in JSON, but it is helpful to learn and recognize them. Objects, Arrays, strings, etc. http://www.json.org/ and http://www.w3schools.com/json/default.asp are good resources to get started. For example a string array in JSON would look like,