0

Can anyone tell me how to get a value from a json array in Android. The array has no name

Json arrays in Android Java

10th Jul 2018, 12:05 PM
Tinovimba Mawoyo
Tinovimba Mawoyo - avatar
9 Answers
0
Ok, firstly you can turn it into a JavaScript variable like this: var myJson = [ { "title" : "messages" } { "title" : "store" } ]; Then you can start selecting, using either keys or property names. For the first object, the key is 0. Put it in square brackets like this. var firstObj = myJson[0];
10th Jul 2018, 12:39 PM
James
James - avatar
0
JSON files are objects not arrays. So what you are saying is that the file just begins with curly brackets like { and no other code?
10th Jul 2018, 12:32 PM
James
James - avatar
0
yes inside the json object is an array, i know how to retrieve values where arrays have names but what about where the arrays have no names
10th Jul 2018, 12:33 PM
Tinovimba Mawoyo
Tinovimba Mawoyo - avatar
0
Can you show me part of it?
10th Jul 2018, 12:34 PM
James
James - avatar
0
it's like this [ { "title" : "messages" } { "title" : "store" } ]
10th Jul 2018, 12:35 PM
Tinovimba Mawoyo
Tinovimba Mawoyo - avatar
0
firstly i want to retrieve the first object only
10th Jul 2018, 12:37 PM
Tinovimba Mawoyo
Tinovimba Mawoyo - avatar
0
i am using an API and I'm using java so can you explain in JAVA
10th Jul 2018, 12:40 PM
Tinovimba Mawoyo
Tinovimba Mawoyo - avatar
0
Oops. I think it would be the same, just use String[] instead of var. String[] myJson = //JSON here
10th Jul 2018, 12:44 PM
James
James - avatar
0
thanks I'll try that and get back to you with the results
10th Jul 2018, 12:45 PM
Tinovimba Mawoyo
Tinovimba Mawoyo - avatar