title: Unable to parse JSON array in Android app
body: <p>I have an Android app that uses bar code scanner library. All is working good, until I have created an Activity that is called after the scanning is done. </p>
  
  <p>That Activity uses this JSON array:</p>
  
  <pre><code>&lt;?php
  $barCodes = array(
  array(
      "id" =&gt; 123456,
      "format" =&gt; "upc_1"
  ),
  array(
      "id" =&gt; 39123439,
      "format" =&gt; "upc_2"
  ),
  array(
      "id" =&gt; 12345670,
      "format" =&gt; "upc_3"
    )
  );
  </code></pre>
  
  <p>echo json_encode($barCodes);
     ?></p>
  
  <p>and the code to parse this JSONArray is:</p>
  
  <pre><code>   String scanResult;
  
     Intent intent = getIntent();
     scanResult = intent.getStringExtra("result");
  
  
  HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://someAddress.php");
  
  
    try {
  
     HttpResponse response = httpclient.execute(httppost);
     String jsonResult = inputStreamToString(response.getEntity().getContent()).toString();
  
  
     JSONObject object = new JSONObject(jsonResult);
  
     JSONArray jArray = object.getJSONArray("barCodes");
  
     JSONObject json_data;
     int id ;
     String format ;
     String ret_format[] = new String[jArray.length()];
     int ret_id[] = new int[jArray.length()];
  
     for(int i=0;i&lt;jArray.length();i++){
          json_data = jArray.getJSONObject(i);
  
          id =    json_data.getInt("id");
          format = json_data.getString("format");
  
          ret_id[i] = id;
          ret_format[i] = format;
         }
  
  
        int scanInt = Integer.parseInt(scanResult);
  
        switch(scanInt) {
  
        case 123456:
            textView.setText(ret_id[0] + " - " + ret_format[0]);  
        break;
  
        case 39123439:
            textView.setText(ret_id[1] + " - " + ret_format[1]);  
        break;
  
        case 12345670:
            textView.setText(ret_id[2] + " - " + ret_format[2]);  
        break;
  
        default:
            textView.setText("Result doesn't match the codes available...");
        break;
  
        }
  
    } 
    catch (JSONException e) {
     e.printStackTrace();
    } 
    catch (ClientProtocolException e) {
     e.printStackTrace();
    } 
    catch (IOException e) {
     e.printStackTrace();
    }
  
  }
  
  private StringBuilder inputStreamToString(InputStream is) {
          String rLine = "";
          StringBuilder answer = new StringBuilder();
          BufferedReader rd = new BufferedReader(new InputStreamReader(is));
  
          try {
           while ((rLine = rd.readLine()) != null) {
            answer.append(rLine);
             }
          }
  
          catch (IOException e) {
              e.printStackTrace();
           }
          return answer;
         }
  </code></pre>
  
  <p>app is working without errors, but it is not displaying any result from the switch statement. I do not know where is the problem. Someone here may have had the same problem, so please help me.</p>
  
  <p>Thanks.</p>