I have a big problem parsing JSON
in C#
in Windows Phone 8 app.
The application close when I try to execute this part of the code. The problem append when the C# code deserialize json.
See below the code : C# (deserialization + class forms) and JSON
result.
Thanks for your answers.
public partial class MyGrades : PhoneApplicationPage
{
string token = string.Empty;
string mail = string.Empty;
public class MyGradesJson
{
[JsonProperty("periods")]
public Periods periods { get; set; }
}
public class Periods
{
[JsonProperty("period")]
public List<Perioddata> perioddata { get; set; }
}
public class Perioddata
{
[JsonProperty("period")]
public Period period { get; set; }
// [JsonProperty("name")]
// public List disciplines { get; set; }
}
public class Period
{
[JsonProperty("id")]
public int id { get; set; }
[JsonProperty("name")]
public string name { get; set; }
[JsonProperty("start_date")]
public string start_date { get; set; }
[JsonProperty("end_date")]
public string end_date { get; set; }
}
HttpResponseMessage response = await httpClient.SendAsync(requestMessage);
string responseAsString = await response.Content.ReadAsStringAsync();
var resJson = JsonConvert.DeserializeObject<Periods>(responseAsString);
}
Here is the Json answer :
{
"periods":[
{
"period":{
"id":1,
"name":"Year 1",
"start_date":"2000-01-01",
"end_date":"2001-06-30"
},
"disciplines":[
{
"discipline":{
"id":6,
"name":"Potions"
},
"grades":[
{
"id":11,
"note":2,
"coefficient":2,
"assessment":"yolo",
"teacher":{
"id":2,
"user_id":4,
"login":"snape_se",
"name":"Snape, Severus"
}
},
{
"id":15,
"note":10,
"coefficient":1,
"assessment":"test",
"teacher":{
"id":2,
"user_id":4,
"login":"snape_se",
"name":"Snape, Severus"
}
}
]
}
]
}
]
}