Parsing Json C#
我在WindowsPhone8应用程序中解析
当我尝试执行这部分代码时,应用程序将关闭。当C代码反序列化JSON时,问题会附加。
见下面的代码:c(反序列化+类形式)和
谢谢你的回答。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 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); } |
下面是JSON的答案:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | { "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" } } ] } ] } ] } |
我认为你的应用程序坏了,因为你的