title: Android - parsing JSON strings in Java
body: <p>I've got a JSON string and I'm just trying to access the different properties of it and store them in Java variables. However, I keep getting an exception with the following code:</p>
  
  <pre><code>    private JSONObject jObj; 
      private String jString; 
  
  //...
  jString = result; //this is my JSON string passed from another activity
          try {
  
              jObj = new JSONObject(jString);
              //int eventID = jObj.getInt("eventID"); 
  
  
  
  
  
          } catch (JSONException e) {
              Toast.makeText(searchResultsActivity.this, "Search results failed!", Toast.LENGTH_SHORT).show();
              finish(); 
          } 
  </code></pre>
  
  <p>Yes I have the required imports. I've displayed jString on its own to confirm that it's valid JSON. I'm kind of lost because this seems to be the most basic thing I need to do. Thanks for any help guys. </p>
  
  <p>EDIT - here is an example JSON string: </p>
  
  <p>[{"eventID":"47","event_name":"test","event_address":"Test","event_duration":"3","event_date":"20110527","event_time":"1347","event_description":"Test","num_attending":"1"}]</p>
  
  <p>This string is received through a PHP script where I do echo json_encode($array), where $array is the associative array creating this JSON response. </p>
  
  <p>The exception I get is:</p>
  
  <p>"org.json.JSONException: Value[//above JSON string//] of type org.json.JSONArray cannot be converted to JSONObject"</p>