Skip to content Skip to sidebar Skip to footer

Org.json.jsonobject$1 Cannot Be Converted To Jsonobject Error While Parsing Json String

For parsing json i use JSONArray and JsonObject: protected void parseJson() { JSONObject object=null; try { object=new JSONObject(json);

Solution 1:

if(obj.length() == 0)

is what I would do.

JSONObject fetchObject;

if(flowerArray.getJSONObject(i).length() !=0)

/

fetchObject = flowerArray.getJSONObject(i)
    if(fetchObject== null)

Solution 2:

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

protectedvoidparseJson()
    {
        JSONObjectobject=null;
        try {

            object=newJSONObject(json);
            myArray=object.getJSONArray(MY_ARRAY);
            Log.e("Array Length",""+myArray.length());
            key_id=newString[myArray.length()];
            key_name=newString[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();
        }
    }

Post a Comment for "Org.json.jsonobject$1 Cannot Be Converted To Jsonobject Error While Parsing Json String"