I need to get latitude and longitude to my android, it got many values like this :

I tried this to get values from JSON :
ArrayList<String> longitude;
ArrayList<String> latitude;
public void parseJson(String result) {
try {
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject jo = jArray.getJSONObject(i);
latitude.add(jo.getString("Latitude").toString());
longitude.add(jo.getString("Longitude").toString());
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
}
But When I check the size of array, it’s empty.
Anyone can help or suggest my wrong ? Thanks
@after modified,I still got 0 size of array. So,I tried to search where it’s stop by Toast then I found :
public void parseJson(String result) throws JSONException {
longitude = new ArrayList<String>();
latitude = new ArrayList<String>();
JSONArray jArray = (JSONArray)JSONValue.parse(result);
for (Object obj: jArray) {
JSONObject jo = (JSONObject)obj;
//here is when I toast it's got nothing
latitude.add(jo.get("Latitude").toString());
longitude.add(jo.get("Longitude").toString());
}
}
@aroth I got an answer!! I back to use my way like this :
public void parseJson(String result) throws JSONException {
longitude = new ArrayList<String>();
latitude = new ArrayList<String>();
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject jo = jArray.getJSONObject(i);
latitude.add(jo.getString("Latitude").toString());
longitude.add(jo.getString("Longitude").toString());
}
I think I forgot declare these:
longitude = new ArrayList<String>();
latitude = new ArrayList<String>();
I still no idea why your code is not work. However, thank a lot for your help :))
The json.org library is needlessly obtuse with its
get<Type>methods that all pointlessly throwJSONException, I would recommend switching to simple-json. Then you could do:Should work, assuming your input JSON matches your example snippet.