Nested JSON array returning null In WinRT

I am trying to connect WebApi application with Windows RT app. I receive the Json correctly from the page. I get all elements asynchronous from JSON array the unique problem is that the nested array is returning null but when i debug the json string has element inside Here go the imges and code for MVC 4 and WinRT StudentCollection.cs private async void GetStudents() { HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(new Uri("http://localhost:17775/api/Students")); var json = await response.Content.ReadAsStringAsync(); var jsarray = JsonArray.Parse(json); GetStudentsbyJson(jsarray); } private void GetStudentsbyJson(JsonArray result) { foreach( var item in result) { Student student = new Student(); Course course ; var obj = item.GetObject(); foreach (var key in obj.Keys) { IJsonValue value; if(!obj.TryGetValue(key,out value)) continue; switch (key) { case "ID": student.ID = Int32.Parse(value.GetNumber().ToString()); break; case "Name": student.Name = value.GetString(); break; case "Age": student.Age = Int32.Parse(value.GetNumber().ToString()); break; case "HasScholarship": student.HasScholarship = value.GetBoolean(); break; case "Course": course= GetCourseJson( value.GetObject()); break; case "Sex": student.Sex = value.GetString(); break; } } if (student != null) _students.Add(student); } } private Course GetCourseJson(JsonObject jsonObject) { var course = new Course(); foreach (var key in jsonObject.Keys) { IJsonValue value; if (!jsonObject.TryGetValue("keys", out value)) continue; switch (key) { case "CourseId": course.CourseId = Int32.Parse(value.ToString()); break; case "Name": course.Name = value.GetString(); if (course.Name == null) throw new NullReferenceException("No Name added"); break; } } return course != null ? course : new Course() {Name="Contabilidade" }; } MainPage.xaml ![enter image description here][1] [{"Course":{"CourseId":1,"Name":"Engenharia Informatica"},"ID":1,"Name":"Oldemiro","Age":20,"Sex":"male","HasScholarship":true},{"Course":{"CourseId":1,"Name":"Engenharia Informatica"},"ID":2,"Name":"Teotonio","Age":20,"Sex":"male","HasScholarship":false},{"Course":{"CourseId":1,"Name":"Engenharia Informatica"},"ID":3,"Name":"Ivan Ernesto","Age":21,"Sex":"male","HasScholarship":true},{"Course":{"CourseId":1,"Name":"Engenharia Informatica"},"ID":4,"Name":"Severino Mateus","Age":20,"Sex":"male","HasScholarship":true}] [1]: http://i.stack.imgur.com/mdHie.png

以上就是Nested JSON array returning null In WinRT的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JSON 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏