/ / Parsing JSON Array and Objects - java, android

Parsing JSON Array and Objects - java, android

Voglio recuperare l'elenco dei giocatori di football tramite API, ho fatto correttamente il gestore Http e la API. Ora ho questo array JSON

http://api.football-data.org/v1/teams/66/players

Voglio analizzarlo in modo che venga mostrato solo il nome dei giocatori. Come posso analizzare il primo bit dell'array JSON in modo che l'array inizi da [{name: Paul Pogba ... per favore?

Primo bit dell'array JSON che voglio passare

Il mio codice finora:

@Override
protected Void doInBackground(Void... arg0) {
//New instance of http
http sh = new http();

// Making a request to URL and getting response
final String jsonStr = sh.makeServiceCall(url);

Log.e(TAG, "Response from: " + jsonStr);

if (jsonStr != null) {
try {
// Getting JSON Array node
JSONArray jsonarray = new JSONArray(jsonStr);


for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jo = jsonarray.getJSONObject(i);

String name = jo.getString("name");

HashMap<String, String> player = new HashMap<>();

player.put("name", name);

playerlist.add(player);
}
} catch (final JSONException e) { //In case an error regarding JSON parsing takes place
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG)
.show();
}
});

}
} else {
Log.e(TAG, "Couldn"t get json from server."); //In case the JSON can"t be obtained from the server
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Couldn"t get JSON from server. Check LogCat for possible errors!",
Toast.LENGTH_LONG)
.show();
}
});

}

return null;
}

risposte:

0 per risposta № 1

Grazie per le informazioni ragazzi. Risolto problema con sottostringa :)