I am working on an Android project and my json strings are a bit strange, all of the tutorials are showing that I need to parse an JSONArray but my JSON has no array name.
Heres an example json url. (my understanding says that there needs to be something like “article” before the [
[
///Something should be here
{
"id": 15483,
"title": "Bilbo Baggins is Cool",
"permalink": "http://example.com/2012/12/03/",
"content": "Hello World",
"date": "2012-12-03 00:04:08",
"author": "Bilbo Baggins",
"thumbnail": "http://example.com/wp- content/uploads/2012/12/DSC02971.jpg",
"categories": [
"News"
],
"tags": [
"LOTR",
"One Ring",
"Patch",
"Police Department"
]
}
]
Like this example http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
They have a tag at the beginning called “contacts” which lets him use a JSONArray to loop through all the contents and get the tags…
I am lost.
How can I parse this data? the tutorial code would not work as I cannot pull an array(as least i think).
First of all,I would like to tell you that in the example of androidhive,the
rootelement of jsonstring is thejsonobjectand therootelement of jsonstring which you posted as question is thejsonarray.Second of all,It’s not necessary to always have a name at the beginning of array to consume it and extract data from it.but yes,it surely requires in complex cases and it is good practice too.
the root element is different,so you need to change the way of consuming the data,
in example of androidhive,
the jsonstring which you posted as question can be consumed in JSONArray,