[Solved] org.json.JSONObject$1 cannot be converted to JSONObject error while parsing json string


After reading JsonArray and JsonObject doc i understand how to sort out this problem.

protected void parseJson()
    {
        JSONObject object=null;
        try {

            object=new JSONObject(json);
            myArray=object.getJSONArray(MY_ARRAY);
            Log.e("Array Length",""+myArray.length());
            key_id=new String[myArray.length()];
            key_name=new String[myArray.length()];

            for (int i=0;i<=myArray.length();i++)
            {

                JSONObject fetchObject=myArray.optJSONObject(i);

                    if(fetchObject==null)
                   {
                     //do nothing
                   }
                   else
                   {
                    key_id[i] = fetchObject.getString(KEY_ID);
                    key_name[i] = fetchObject.getString(KEY_NAME);

                   }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

1

solved org.json.JSONObject$1 cannot be converted to JSONObject error while parsing json string