I am not much experienced in JSON, so the question might be a little trivial, but I can not sort this out. I have a simple JSON string like:
["{\"__type:\"GeoPoint\",\"latitude\":51.165691,\"longitude\":10.451526}","{\"__type:\"GeoPoint\",\"latitude\":20.593684,\"longitude\":78.96288}"]
I want to parse the JSON and get the values in different variables. I have implemented the below code snippet but it is not working as expected. I can see no log after parsing the JSON. The code:
String jsonString = arg0.get(i).get(0).getJSONArray("tripPoints").toString();
Log.e("Json String", jsonString);
JSONArray jsonarray;
try {
jsonarray = new JSONArray(jsonString);
for(int j=0; j<jsonarray.length(); j++){
JSONObject obj = jsonarray.getJSONObject(j);
String latitude = obj.getString("latitude");
String longitude = obj.getString("longitude");
Log.e("triplatitude", latitude);
Log.e("triplongitude", longitude);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
What should I do to get the data from the JSON? Where am I going wrong?