Reese Reese - 1 year ago 249
JSON Question

c# - Convert JSON to array

I'm using Newtonsoft JSON.

Newtonsoft.Json.Linq.JArray userLists = Newtonsoft.Json.Linq.JArray.Parse(result)

"result" contains:


What's wrong? The messagebox is empty and at index 1 it throws an error.
Thanks in advance.

Answer Source

Your JSON does not contain an array but rather an object. You can access it via the string index:

var o = JObject.Parse("{'response':'1','0':{'id':'1','username':'bla','name':'bla '},'1':{'id':'2','username':'blub','name':'blub'}}");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download