这是jsonArray:
JSONArray jsonArray = CommonFunctions.GetJSONResults(url, parameters);
CoursesEntity [] CourseDetail=new CoursesEntity[jsonArray.length()];
这里是jsonArray的值,我在执行上面的行之后得到了:
[
{
"UserCourseId": 253,
"EnrollDate": "2014-05-28T17:54:31.733",
"Status": 0,
"IsThirdPartyCourse": true,
"MappedCourseUrl": "a",
"MappedUserId": "a",
"Id": 15,
"Name": "Diabetes Management",
"ShortName": null,
"Synopsis": null,
"Description": null,
"Duration": "7",
"ImagePath": "S.jpg",
"IsNewCourse": 0,
"IsDisplayEnrollUnenroll": 0,
"InstituteName": null,
"CourseAuthor": null,
"CourseLink": null
},
{
"UserCourseId": 253,
"EnrollDate": "2014-05-28T17:54:31.733",
"Status": 0,
"IsThirdPartyCourse": true,
"MappedCourseUrl": "a",
"MappedUserId": "a",
"Id": 15,
"Name": "Diabetes Management",
"ShortName": null,
"Synopsis": null,
"Description": null,
"Duration": "7",
"ImagePath": "S.jpg",
"IsNewCourse": 0,
"IsDisplayEnrollUnenroll": 0,
"InstituteName": null,
"CourseAuthor": null,
"CourseLink": null
},
{
"UserCourseId": 253,
"EnrollDate": "2014-05-28T17:54:31.733",
"Status": 0,
"IsThirdPartyCourse": true,
"MappedCourseUrl": "a",
"MappedUserId": "a",
"Id": 15,
"Name": "Diabetes Management",
"ShortName": null,
"Synopsis": null,
"Description": null,
"Duration": "7",
"ImagePath": "S.jpg",
"IsNewCourse": 0,
"IsDisplayEnrollUnenroll": 0,
"InstituteName": null,
"CourseAuthor": null,
"CourseLink": null
}
]
如何获取这些值?
我尝试过如下,但它变为空:
CourseDetail[i].setCourseName(jsonObj.getJSONObject(i).getString("Name"));
答案 0 :(得分:2)
For(int i=0; JsonArray.length(); i++)
{
JSONObject jsonObj = JsonArray.getJSONObject(i);
CourseDetail[i].setCourseName(jsonObj.getString("Name"));
... ...
}
希望这有帮助!