title: How to Parse JSONObject and JSONArray at one time
body: <p>i'm working on an app that uses JSON Responses which has both JSONObject and JSONArray. Both the information are required to place markers on map. But i'm facing problem in parsing both. </p>
  
  <p>This is my Response when I called my URl</p>
  
  <pre><code>{
  -source: {
  LS: " ABCDEF",
  name: "XYXA",
  point: "77.583859,12.928751"
  },
   -stores: [
      -{
      ph: null,
      distance: "0.3",
      LS: " abcd",
      id: 1209,
      name: "xyz",
      point: "77.583835,12.926359"
      },
  -{
      ph: null,
      distance: "0.3",
      LS: " abcd",
      id: 1209,
      name: "xyz",
      point: "77.583835,12.926359"
      }
      ]
  }
  </code></pre>
  
  <p>This is how I tried to handle JSON response</p>
  
  <pre><code>public class JSONResponseHandler implements ResponseHandler&lt;List&lt;LatlongRec&gt;&gt; {
          @Override
          public List&lt;LatlongRec&gt; handleResponse(HttpResponse response)
                  throws ClientProtocolException, IOException {
              List&lt;LatlongRec&gt; result = new ArrayList&lt;LatlongRec&gt;();
              String JSONResponse = new BasicResponseHandler()
                      .handleResponse(response);
  
  
              try {
  
                  JSONObject object = (JSONObject)new JSONTokener(JSONResponse)
                          .nextValue();
  
                  JSONArray stores = object.getJSONArray("stores");
                  for (int i = 0; i &lt; stores.length(); i++) {
                      JSONObject tmp = (JSONObject) stores.get(i);
                      result.add(new LatlongRec(tmp.getString("point"), tmp
                              .getString("name"), tmp.getString("LS"), tmp
                              .getString("ph")));
                      Log.v("points", "" + tmp.getString("point"));
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
              return result;
          }
      }
  </code></pre>
  
  <p>In this LatlongRec is a class where I have created constructor and getters.</p>
  
  <p>This is my Main Activity</p>
  
  <pre><code>public class SecondActivity extends Activity {
      private static final double CAMERA_LNG = 77.583859;
      private static final double CAMERA_LAT = 12.928751;
      // The Map Object
      private GoogleMap mMap;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_second);
          String city = getIntent().getStringExtra("city");
          String area1 = getIntent().getStringExtra("area");
          String area = area1.trim();
  
          String URL = "http://xyzxyz.search.json?query="
                  + area + "&amp;city=" + city + "&amp;app_id=test";
          new HttpGetTask().execute(URL);
      }
  
      private class HttpGetTask extends AsyncTask&lt;String, Void, List&lt;LatlongRec&gt;&gt; {
          AndroidHttpClient mClient = AndroidHttpClient.newInstance("");
  
          @Override
          protected List&lt;LatlongRec&gt; doInBackground(String... params) {
              HttpGet request = new HttpGet(params[0]);
              JSONResponseHandler responseHandler = new JSONResponseHandler();
              try {
  
                  return mClient.execute(request, responseHandler);
              } catch (ClientProtocolException e) {
              } catch (IOException e) {
              }
              return null;
          }
  
          @SuppressLint("NewApi")
          protected void onPostExecute(List&lt;LatlongRec&gt; result) {
              // Get Map Object
              mMap = ((MapFragment) getFragmentManager().findFragmentById(
                      R.id.map)).getMap();
              if (null != mMap) {
                  // Add a marker for every earthquake
                  for (final LatlongRec rec : result) {
                      Log.v("pointM", "" + rec.getPoint());
                      Log.v("NAMES", "" + rec.getName());
  
                      String point = rec.getPoint();
                      String[] latlng = point.split(",");
                      String lat = latlng[0];
                      String lng = latlng[1];
  
                      Double lat1 = Double.parseDouble(lat);
                      Double lng1 = Double.parseDouble(lng);
  
  
  
                      Log.v("LATLNGM", "lat" + lng + "&amp; lng " + lat);
                      // Add a new marker for each point
                      mMap.addMarker(new MarkerOptions()
                              .position(new LatLng(lng1, lat1))
                              .title(rec.getName())
                              .snippet(rec.getLS() + rec.getPh())
                              .icon(BitmapDescriptorFactory
                                      .fromResource(R.drawable.main_marker)));
                  // Setting a custom info window adapter for the google map
                  CameraPosition cp = new CameraPosition(new LatLng(CAMERA_LAT,
                          CAMERA_LNG), 15, 40, 90);
                  mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
              }
              if (null != mClient)
                  mClient.close();
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.second, menu);
          return true;
      }
  }
  </code></pre>
  
  <p>How to get points in source object to my main activity so that i can set CAMERA_LAT and CAMERA_LNG to Lat and Lng from that point.?</p>
  
  <p>I'm new to JSON please help me to solve this.</p>
  
  <p>Thanking you</p>