Skip to content Skip to sidebar Skip to footer

Json Error: Value Sl_summ Of Type Java.lang.string Cannot Be Converted To Json Object

How to fix this error. Hope you can guide me how to solve this problem I encountered my just new to android programming. I only followed the code in a tutorail and make some change

Solution 1:

From what I see in your message log, is that you're trying to convert this :

LoginResponse: {"error":false,"user":{"br_code":12,"mem_id":13,"username":"test","email":"test@yahoo.com","created_at":"2016-07-22 09:05:21"}}<br /><br />{"error":false,"sl_summ":{"sl_desc":"PA : Savings Account","tr_date":"2015-08-17","actual_balance":"483.67","available_balance":"483.67"}}{"error":false,"sl_summ":{"sl_desc":"PA : Savings - Cash Bond","tr_date":"2015-08-28","actual_balance":"10129.43","available_balance":"10129.43"}}

into a JSONObject.

And I see at least 2 errors in this :

  • There is some HTML element : <br /><br /> that you need to remove first.
  • There is multiple JSON file

So, after removing the HTML elements, you will need to either :

  • Parse that Login Response, and make multiple JSON Object;
  • Or create a JSON Array out of your Login Response.

You can use this website to validate your JSON.

Solution 2:

This is happening because of your <br /> tag in response.

You are having your response as

LoginResponse: {"error":false,"user":{"br_code":12,"mem_id":13,"username":"test","email":"test@yahoo.com","created_at":"2016-07-22 09:05:21"}}<br /><br />{"error":false,"sl_summ":{"sl_desc":"PA : Savings Account","tr_date":"2015-08-17","actual_balance":"483.67","available_balance":"483.67"}}{"error":false,"sl_summ":{"sl_desc":"PA : Savings - Cash Bond","tr_date":"2015-08-28","actual_balance":"10129.43","available_balance":"10129.43"}}

these <br> tags are because of you php code.

Also your sl_summ is not an jsonArray. Its a Json object.

{"error":false,"sl_summ":{"sl_desc":"PA : Savings Account","tr_date":"2015-08-17","actual_balance":"483.67","available_balance":"483.67"}}{"error":false,"sl_summ":{"sl_desc":"PA : Savings - Cash Bond","tr_date":"2015-08-28","actual_balance":"10129.43","available_balance":"10129.43"}}

so when you are writing JSONArray sl_summ = sl_jObj.optJSONArray("sl_summ"); This JsonObject is not converted to JsonArray that in turn giving you error.

You should correct your json as,

{"error":false,"sl_summ":[{"sl_desc":"PA : Savings Account","tr_date":"2015-08-17","actual_balance":"483.67","available_balance":"483.67"},{"sl_desc":"PA : Savings - Cash Bond","tr_date":"2015-08-28","actual_balance":"10129.43","available_balance":"10129.43"}]}

Solution 3:

Change your jsonobect for sl_summ like this

JsonObject  json =  newJsonObject(response);
          if(json.has("sl_summ"){

         JSONObject sl_jObj  = newJSONObject(json.getString("sl_summ"));
}

Post a Comment for "Json Error: Value Sl_summ Of Type Java.lang.string Cannot Be Converted To Json Object"