My Json Object :
"feedback_details":{
"id":"80",
"lead_id":"86075",
"account_id":"1543",
"document_id":"582348",
"reason_id":"4",
"description":"COAPPL_profile1.jpg",
"sales_remark":null,
"lat":"",
"long":"",
"status":"2",
"created_at":"2018-02-27 12:29:59",
"updated_at":"2018-02-27 12:29:59"
}
When i have no details in feedback_details then it comes to an empty json array like this :
"feedback_details":[
]
So i tried converting it forcefully to a blank json object :
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
for (int j = 0; j < object.getJSONArray("applicantPhoto").length(); j++) {
object.getJSONArray("applicantPhoto").getJSONObject(j);
if (object.getJSONArray("applicantPhoto").getJSONObject(j).optJSONObject("feedback_details") == null) {
new JSONObject(object.getJSONArray("applicantPhoto").getJSONObject(j).getString("feedback_details"));
}
if (object.getJSONArray("applicantSignatire").getJSONObject(j).optJSONObject("feedback_details") == null) {
String newstring = object.getJSONArray("applicantSignatire").getJSONObject(j).getJSONArray("feedback_details").toString();
//here i get the exception for type mismatch where the string is "[]"
new JSONObject(newstring);
}
if (object.getJSONArray("applicantPhoto").getJSONObject(j).optJSONObject("feedback_details") == null) {
new JSONObject(String.valueOf(object.getJSONArray("applicantPhoto").getJSONObject(j).getJSONArray("feedback_details")));
}
}
Utility.printMessage("Json object..." + object);
I know that string is "[]", hence it showing an exception as Cannot be converted to JsonObject. Can anyone suggest how to handle this, basically i need an empty object instead of that blank array.