Eventuali duplicati:
JSON Array iteration in Android/JavaCome analizzare la stringa json in Android?
sto recupero stringa JSON dal server e ho già ottenuto stringa JSON dal codice. Ma non ho capito come analizzarlo.
Qui di seguito è la mia stringa JSON
{
"university": {
"name": "oxford",
"url": "http://www.youtube.com"
},
"1": {
"id": "2",
"title": "Baseball",
"datetime": "2011-11-11 10:41:46"
},
"2": {
"id": "1",
"title": "Two basketball team players earn all state honors",
"datetime": "2011-11-11 10:40:57"
}
}
Si prega di fornire alcuna guida o frammento di codice.
è possibile ottenere quanti oggetti in stringa json – helloDroid
Sì, è sufficiente utilizzare "mainObject.length();" – Arslan
Modificato per usare 'getString()' invece di 'getJSONObject()' quando si ottengono valori stringa. L'uso di 'getJSONObject()' ha causato una JSONException quando ho eseguito un codice simile che è stato corretto usando 'getString()'. – Shef