Skip to content Skip to sidebar Skip to footer

What Is The Error Denotes In Android(json) Error Parsing Data Org.json.jsonexception:

Error parsing data org.json.JSONException: Value of type java.lang.String cannot be converted to JSONArray JSONArray jsonArray = new JSONArray(result); JSO

Solution 1:

To your parsing problem its already answered @

How to call the JSON object in Android

Its a string

String secondvalue = jb.getString("CUSTOMER_ID");
try
{
   int value = Integer.parseInt("secondvalue");
   Log.i("Customer id",""+value);
}catch(NumberFormatException e)
{
  e.printStackTrace();
}

Edit:

String myjson ="["+"["+"{"+" \"0\": \"2\","+"\"CUSTOMER_ID\": \"2\""+"}"+"]"+"]";

Parsing

try {
        JSONArray jsonArray = newJSONArray(myjson);
        JSONArray ja= (JSONArray) jsonArray.get(0);
        JSONObject jb = (JSONObject) ja.get(0);
        String firstvalue = jb.getString("0");
        String secondvalue = jb.getString("CUSTOMER_ID");
        int value = Integer.parseInt(secondvalue);
        Log.i("Customer id",""+value);
        Log.i("first value is",firstvalue);
        Log.i("second value is",secondvalue);
    }catch(NumberFormatException e)
     {
    e.printStackTrace();
    }catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Solution 2:

It simply means that the String (say, some_string) you have given as input to the new JSONArray(some_string) can not be converted to a JSON Array because the string does not follow the required json array format. An example of a proper JSON Array string is given below

[ { "title":"title_1", "name":"name_1" }, { "title":"title_2", "name":"name_2" } ]

Post a Comment for "What Is The Error Denotes In Android(json) Error Parsing Data Org.json.jsonexception:"