My app was working fine but suddenly it start giving me erros JSONException: No value for myRating
. I know it's means the value doesn't exist on JSON but i cross check dozens times that myRating exist in JSON i received and i am also able to get other values from same node.
Here is my JSON
{
"status": "SUCCESS",
"uData": [
{
"User_ID": "210",
"First_Name": "Alex ",
"Image": "947d051925ba2014f231f17ffc04db6616645163211632870246.jpg",
"coverPhoto": "1ce295d101204be40363f1e11301ed97d41d8cd98f00b204e9800998ecf8427e16645163211188778355.jpg",
"Gender": "Male",
"login_status": "0",
"myRating": "5.00",
"coverImageID": "354",
"ProfileImageID": "343",
"show_onlineStatus_check": "1",
"verify": "1"
},
{
"User_ID": "4",
"First_Name": "John",
"Image": "cf867d87b655591cbda928287da1ca3616520548151008802.jpg",
"coverPhoto": "0323e6cfa77488abce52aa273e2f5f8e16523048561229563452.jpg",
"Gender": "Female",
"login_status": "0",
"myRating": "5.00",
"distance_check": "1",
"coverImageID": "173",
"ProfileImageID": "174",
"show_onlineStatus_check": "1",
"verify": "2"
}
],
"record": 3,
"uCounter": "50"
}
That's how i am parsing JSON into my app
JSONObject parentArray = new JSONObject(completeJSON);
Log.d(TAG, "Parent Array " + parentArray);
JSONArray jsonArray = parentArray.getJSONArray("uData");
String profileCounter = parentArray.getString("uCounter");
Log.d(TAG, "JSON Array Of UDATA " + jsonArray); // User Data Where I have myRating node
String ImageURL, UserID, Distance, CoverPhoto, myRatings = null;
int Rec_Online_Status;
int distance_check, onlineStatus, verifyProfile;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject childObject = jsonArray.getJSONObject(i);
String Fname = childObject.getString("First_Name");
ImageURL = childObject.getString("Image");
CoverPhoto = childObject.getString("coverPhoto");
UserID = childObject.getString("User_ID");
String gender = childObject.getString("Gender");
Rec_Online_Status = childObject.getInt("login_status");
distance_check = Integer.parseInt(childObject.getString("distance_check"));
onlineStatus = Integer.parseInt(childObject.getString("show_onlineStatus_check"));
verifyProfile = Integer.parseInt(childObject.getString("verify"));
boolean testValue = childObject.has("myRating");
Log.d(TAG, "doInBackground: Test Log = "+testValue);// This also return False
myRatings = childObject.getString("myRating");// JSONException: No value for myRating
int profileID = Integer.parseInt(childObject.getString("ProfileImageID"));
int coverID = Integer.parseInt(childObject.getString("coverImageID"));
}
I am really not sure what i am doing wrong and when value exist in same node it should get fetched but as you can see i am getting exception. Can anyone help me out in this. The is required to run app so i am not using has
or optString
.