I have a JSON like this :
{
- 0: {
"title": "Title1",
"content": "test"
},
- 1: {
"title": "Title2",
"content": "test2"
}
}
So i want to recover it in my application, and i have an exception with this line :
JSONArray jArray = new JSONArray(result);
I checked that "result" contains my JSON, and it's the case.
When i see the error in the logcat i just see values of my JSON.... i have something like that :
org.json.JSONException and values of my JSON
Could someone help me ?
-
can you add complete logcat exception,if possible.Harshal Benake– Harshal Benake2014年03月18日 10:56:55 +00:00Commented Mar 18, 2014 at 10:56
3 Answers 3
{ means Object by means if json data starts with a { than it is an object
[ means array by means if json data starts with a [ than it is an array
use
JSONObject jObject = new JSONObject(result);
instead of
JSONArray jArray = new JSONArray(result);
for a simple tutorial and to learn visit
http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
2 Comments
The JSON you posted is not a JSONArray but a JSONObject so you have to change from
JSONArray jArray = new JSONArray(result);
to
JSONObject jObject = new JSONObject(result);
2 Comments
You can get an easy to understand example for encoding and parsing json: Android JSON Tutorial: Create and Parse JSON data
and