purva purva - 4 months ago 9
JSON Question

Fetching Array from Json server?

my android code

json format

i want to get fetch the lat and long of the Trip1 array???

Drv Drv
Answer

Replace your

JSONArray msg=tripObjects.getJSONArray("Trips");
JSONArray msg1=tripObjects.getJSONArray("Trip1");

with

JSONObject msg=tripObjects.getJSONObject("Trips");
JSONArray msg1=msg.getJSONArray("Trip1");

And fetch your lat-long by using for loop on your msg1 array's size as below:

for(int j=0;j<msg1.length();j++){
     JSONObject msgObject=msg1.getJSONObject(j);
     String lat=msgObject.getString("Sfltlattitude");
     String longi=msgObject.getString("SfltLogitude");
}