/ / पार्सिंग जेन्स ऐरे और ऑब्जेक्ट्स - जावा, एंड्रॉइड

JSON ऐरे और ऑब्जेक्ट्स पार्सिंग - जावा, एंड्रॉइड

मैं एपीआई के माध्यम से फुटबॉल खिलाड़ियों की सूची को पुनः प्राप्त करना चाहता हूं, मैंने एचटीपी हैंडलर और एपि कॉल को सही ढंग से बनाया है। अब मेरे पास यह JSON सरणी है

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

मैं इसे पार्स करना चाहता हूं ताकि केवल खिलाड़ियों का नाम दिखाया जाए। मैं JSON सरणी के पहले बिट के माध्यम से पार्स कैसे कर सकता हूं ताकि यह सरणी [{नाम: पॉल पोग्बा ... से शुरू हो?

JSON सरणी का पहला बिट जिसे मैं प्राप्त करना चाहता हूं

मेरा कोड अब तक:

@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;
}

उत्तर:

जवाब के लिए 0 № 1

सूचना के लिए शुक्रिया दोस्तों। इसे सबस्ट्रिंग के साथ तय किया गया :)