My app for Windows Phone have a collection from a JSON (WebService of Google Calendar).
I can get the JSON correctly, but when does the Parse, get an error:
Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path", line 1, position 1.
I not know if this is the problem, but never worked with a complex JSON. Example: the "tag" dateTime
on JSON is "inside" of start
and another inside of end
. How, on my collection, I define this?
JSON response:
{
kind: "calendar#events",
etag: ""1416310700455000"",
summary: "desenvolvimentomobile@ff.com.br",
updated: "2014-11-18T11:38:20.455Z",
timeZone: "America/Sao_Paulo",
accessRole: "reader",
defaultReminders: [ ],
nextSyncToken: "CNjoxMGf",
items: [
{
kind: "calendar#event",
etag: ""283f00"",
id: "sf00g1go9399gf",
status: "confirmed",
htmlLink: "https://www.google.com/calendar/event?eid=c2YwMGcxZ285Mzk5Z3YxcTU2Nml2dGl2b3MfiaWxlQGluZmFzc3RlYy5jb20uYnI",
created: "2014-11-17T17:23:05.000Z",
updated: "2014-11-17T17:23:05.362Z",
summary: "Exemplo 1",
creator: {
email: "desenvolvimentomobile@ifc.com.br",
displayName: "Infass silva",
self: true
},
organizer: {
email: "desenvolvimentomobile@ifc.com.br",
displayName: "Infass silva",
self: true
},
start: {
dateTime: "2014-11-17T17:00:00-02:00"
},
end: {
dateTime: "2014-11-17T18:00:00-02:00"
},
iCalUID: "sf00g1go9399fvtivos@google.com",
sequence: 0
}
]}
C#:
DataContext = this;
// String JSON
string json1 = text;
// Parse JObject
JArray jObj1 = JArray.Parse(json1);
Comp = new ObservableCollection<Compromisso>(
jObj1.Children().Select(jo1 => jo1.ToObject<Compromisso>()));
}
}
}
public ObservableCollection<Compromisso> Comp { get; set; }
public class Compromisso
{
public string summary { get; set; }
public string dateTime { get; set; }
public string location { get; set; }
public string description { get; set; }
}