JSON string:
[{"id":"1","username":"admin","password":"anymd5hash","rank":"2"}]
following code:
Newtonsoft.Json.Linq.JObject userData;
userData = Newtonsoft.Json.Linq.JObject.Parse(result);
MessageBox.Show(userData["username"].ToString());
When I execute this code, there will be an error:
Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
I'm pretty sure, that this code has worked in another project.
What is my mistake?
[and]from your string and try again. It's an array.Newtonsoft.Json.Linq.JArray.Parse. That will accept your existing input.JTokenwould also work for either arrays (what you've got) or objects.JToken.Parse().