Ich habe eine JSON-Datei, die ich analysieren möchte, aber nicht weiß, wie Sie richtig darauf zugreifen.Android Studio: JSON Parsing
Es beginnt nicht mit einer Objektklammer "{" und danach ein Name wie z. "actors:" "[" ....]}
wo ich einfach ein JSONObject jObj = neues JSONObject (Daten) erstellen würde; JSONArray jArray = jObj.getJSONArray ("Akteure");
Mine sieht eher wie dieses
[
{
"type": "fuel",
"name": "Aral",
"address": "Somestreet 65",
"lat": 49.8848387,
"lon": 8.6520691 },
{
"type": "amenity",
"name": "Centralstation",
"address": "Centralstreet 20",
"lat": 49.8725,
"lon": 8.628889,
"icon": "somepicture.jpg" },
]
ich etwas versucht, wie
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(params[0]);
HttpResponse response = client.execute(post);
int status = response.getStatusLine().getStatusCode();
if(status == 200){
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONArray jsonArray = new JSONArray(data);
//JSONObject jsonObject = new JSONObject(data);
for(int i=0; i< jsonArray.length();i++){
Locations location = new Locations();
JSONObject jRealObject = jsonArray.getJSONObject(i);
location.setName(jRealObject.getString("type"));
location.setName(jRealObject.getString("name"));
location.setName(jRealObject.getString("address"));
location.setName(jRealObject.getString("lat"));
location.setName(jRealObject.getString("lon"));
//location.setImage(jRealObject.getString("icon"));
locationList.add(location);
}
return true;
}
}catch (ClientProtocolException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}catch (JSONException e){
e.printStackTrace();
}
return false;
}
Aber es ist ein Fehler, während es das Parsen Ich denke, es hat etwas mit „JSONArray jsonArray = new JSONArray zu tun hat („“);
können Sie mich oder Punkt in einer Richtung helfen, wo ich meine Fehler finden konnte
JSON-Array initialisieren als: JSONArray jasnArray = new JSONArray(); – Akshay
funktioniert nicht für mich –