Desidero recuperare JSON da un servizio Web e analizzarlo in seguito.
Sono sulla buona strada?Come convertire HttpEntity in JSON?
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response;
try {
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
// parsing JSON
}
} catch (Exception e) {
}
Purtroppo non so come convertire HttpEntity
in un JSONObject.
Questo è il mio JSON (estratto):
{
"names": [
{
"name": "Zachary"
},
{
"name": "Wyatt"
},
{
"name": "William"
}
]
}
Si dice 'Tipo non corrispondente: non può convertire da Object a STRING', quindi l'ho cambiato in' stringa di token = (String) result.get ("token"); '. Ma sfortunatamente non ricevo nulla quando provo 'Log.d (" token ", token);', anche se l'entità è '! = Null' e ho JSON valido. – user1170330
ok allora puoi inviarmi il tuo json feed link bez è possibile che il tuo oggetto json contenga un altro JsonArray, allora devi prima usare JSONArray e poi estrarre il valore dall'array –
Si prega di notare l'aggiornamento (codice JSON). – user1170330