Ich habe gerade mit der Android-Entwicklung begonnen und ich stehe vor einem Problem, das ich nicht lösen kann.Stuck Umwandlung von String in JSON
nenne ich eine API in meiner android app Volley
und ich erhalte die folgende Antwort:
[
{
"id": 25,
"user_id": 39,
"positionX": "51.4595484",
"positionY": "5.4757402",
"modified": "2016-12-15T00:00:00"
},
{
"id": 26,
"user_id": 40,
"positionX": "51.4595518",
"positionY": "5.4757409",
"modified": "2016-12-15T00:00:00"
},
{
"id": 27,
"user_id": 41,
"positionX": "51.459554",
"positionY": "5.4757413",
"modified": "2016-12-15T00:00:00"
},
{
"id": 28,
"user_id": 42,
"positionX": "51.459554",
"positionY": "5.4757413",
"modified": "2016-12-15T00:00:00"
}
]
Ich versuche, Daten zu holen aus JSONArray
, aber ich kann es nicht ... funktioniert Dies ist mein Code:
@Override
public void onResponse(String response) {
try {
JSONArray jsonArray = new JSONArray(response);
JSONObject jsonObject = jsonArray.getJSONObject(0);
for (int i = 0; i < jsonObject.length(); i++) {
JSONObject row = jsonObject.getJSONObject();
points.add(new LatLng(row.getDouble("positionX"),row.getDouble("positionY")));
}
Toast.makeText(getApplicationContext(), "Updated users info." + points.get(0).toString(), Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "error" + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
definieren * aber ich kann es nicht funktionieren lassen * auch * Ich stehe vor einem Problem, das ich nicht lösen kann. * Welches Problem? – Selvin
auch, würden Sie wahrscheinlich profitieren von der Verwendung von 'Gson' Bibliothek –
Bitte lesen [diese (wie Sie fragen)] (http://stackoverflow.com/help/how-to-ask) und [this (mcve) ] (http://stackoverflow.com/help/mcve), bevor Sie fragen, , da diese Ihnen helfen werden, mehr und bessere Antworten von der Gemeinschaft zu erhalten. – Bonatti