user4385299
user4385299

Reputation:

How to fetch jsonarray values in android?

Here is jsonArray:

JSONArray jsonArray = CommonFunctions.GetJSONResults(url, parameters);
CoursesEntity [] CourseDetail=new CoursesEntity[jsonArray.length()];


And here is the value of jsonArray, I am getting after executing above line:

   [
    {
        "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
    }
]


How to fetch these values? I tried like below, but it is getting null:

CourseDetail[i].setCourseName(jsonObj.getJSONObject(i).getString("Name"));

Upvotes: 0

Views: 46

Answers (1)

Xcihnegn
Xcihnegn

Reputation: 11607

For(int i=0; JsonArray.length(); i++)
{
   JSONObject jsonObj = JsonArray.getJSONObject(i);
   CourseDetail[i].setCourseName(jsonObj.getString("Name")); 

     ... ...

}

Hope this help!

Upvotes: 2

Related Questions