For parsing json i use JSONArray and JsonObject:
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.getJSONObject(i);
key_id[i] = fetchObject.getString(KEY_ID);
key_name[i] = fetchObject.getString(KEY_NAME);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
JSON DATA:
{
"data": [{
"key": 1,
"myval": "hello"
}, {
"key": 1,
"myval": "hello"
}, {
"key": 1,
"myval": "hello"
}, null, {
"key": 1,
"myval": "hello"
}, {
"key": 1,
"myval": "hello"
}]
}
My problem is that when fetchObject get the null object it give me org.json.JSONObject$1
cannot be converted to JSONObject in try catch .
Please help me how can i solve this.....Thanks for reading....