I'm trying to parse some JSON data with Json.Net. Here is my data:
[     {         "UIDClan": "1",         "UIDKnjiga": "1",         "Naslov": "Title1",         "DatumZaKada": "2013-08-09 00:00:00",         "DatumIstekRez": null,         "Spremno": "0"     },     {         "UIDClan": "1",         "UIDKnjiga": "2",         "Naslov": "Title2",         "DatumZaKada": "2013-08-08 00:00:00",         "DatumIstekRez": null,         "Spremno": "0"     },     {         "UIDClan": "1",         "UIDKnjiga": "3",         "Naslov": "Title3",         "DatumZaKada": "2013-08-09 00:00:00",         "DatumIstekRez": "2013-10-09 00:00:00",         "Spremno": "1"     } ]   With this piece of code i want to extract UIDClan data:
 JObject o = JObject.Parse(s);   Console.WriteLine(o["UIDClan"]);   The error is
Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
I've checked with JSONLint and it's valid.
The examples that I found doesn't start with [.
Am I doing something wrong?
You could try using a JArray. This JSON data is actually an array.
JArray v = JArray.Parse(s);   To get the first item.
var firstItem = v[0]["UIDClan"].ToString();   You can even use linq
var items = v.Where(x =>  x["UIDClan"].ToString() == "1").ToList(); 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With