JSON LInk - http://jsonviewer.stack.hu/#http://www.saveme.ie/api/savings/Android - tableau JSON sans Parsing Nom Array
Im essayant de chercher un JSON pour remplir un ListView dans Android avec cette tâche de fond, mais le dire qu'il ya un problème avec le JSON. Il semble que ce soit parce que le tableau n'a pas de nom.
Comment est-ce que je modifierais le code afin qu'il puisse aller chercher le tableau sans nom?
private class GetSavings extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
HttpHandler sh = new HttpHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url);
Log.e(TAG, "Response from url: " + jsonStr);
if (jsonStr != null) {
try {
**JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
JSONArray savings = jsonObj.getJSONArray("savings");
// looping through All Contacts
for (int i = 0; i < savings.length(); i++) {
JSONObject c = savings.getJSONObject(i);
String title = c.getString("title");
}**
} catch (final JSONException e) {
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.");
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;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
MainActivity.this, savingsList,
R.layout.list_item, new String[]{"name", "email",
"mobile"}, new int[]{R.id.name,
R.id.email, R.id.mobile});
lv.setAdapter(adapter);
}
}
Pourriez-vous partager l'erreur spécifique que vous obtenez? – DCruz22
Premier lien est le JSON - http://jsonviewer.stack.hu/#http://www.saveme.ie/api/savings/ – ChrisM
Ceci est ma réponse - http://stackoverflow.com/a/41616005/ 4741746 –