I am parsing an array of json elements on android. Following line generates following exception. I’ve validated the json file on some validation pages and all seems correct.
What’s wrong?
JSONObject object = new JSONObject(content);
The exception:
org.json.JSONException: Unterminated array at character 21 of {
"info":[
{
"category":"Cocktail",
"text":"Long Island Ice Tea",
"info":"nur am 19. Juni",
"imageUrl":"http://www.google.at/google.png",
"thumbnailUrl":"http://www.google.at/google.png"
},
{
"category":"Grill-Wochen",
"text":"Steak vom Grill 350g",
"info":"AB 16.09.2012",
"imageUrl":"http://www.example.com/example.jpg",
"thumbnailUrl":"http://www.example.com/example_thumb.jpg"
}
]
}
I used a JSON parser online and checked your string. It does have a syntax error.
Analyzing the JSON syntax at JSON.org we can verify that every object must start and finish with curved brackets (“{“). “Info” is an object – so it should be stated as so.
I changed your code to
and the parser was happy with it.
I hope it helps