title: How to create a JSON array in php?
body: <p>I am trying to create a simple android application that takes data from a database and displays it in a list format on the android screen. I made a php script that queries the database and returns a json object. I convert the json object into json array and extract the relevant data for display. But I am getting this error "JSONException: type org.json.JSONObject cannot be converted to JSONArray". </p>
  
  <p>Following is my php script - </p>
  
  <pre><code>       // response Array
  
          $response = array("tag" =&gt; $tag, "success" =&gt; 0, "error" =&gt; 0);
          $username = $_POST['username'];
          $events = $db-&gt;viewAttendingEvent($username);
  
          if ($events) {
          $response["success"] = 1;
          $response["event"]["owner"] = $events["owner"];
          $response["event"]["friendsnames"] = $events["friendsnames"];
          $response["event"]["vote"] = $events["vote"];
          $response["event"]["accepted"] = $events["accepted"];
          $response["event"]["eventname"] = $events["eventname"];
          $response["event"]["eventnumber"] = $events["eventnumber"];
          $response["event"]["created_at"] = $events["created_at"];
          echo json_encode($response);
  </code></pre>
  
  <p>This is the json which I receive back :</p>
  
  <pre><code>{
      "tag": "view_invitations",
      "success": 1,
      "error": 0,
      "event": {
          "owner": "jkkkkoopp",
          "friendsnames": "don",
          "vote": "0",
          "accepted": "f",
          "eventname": "yyy",
          "eventnumber": "11",
          "created_at": "2014-05-29 22:27:31.843528"
      }
  }
  </code></pre>
  
  <p>I am trying to extract 'event' from this json object, which is not an array. 
  it should be </p>
  
  <pre><code>{
      "event": [
          {
              "owner": "jkkkkoopp",
              "friendsnames": "don",
              "vote": "0",
              "accepted": "f",
              "eventname": "yyy",
              "eventnumber": "11",
              "created_at": "2014-05-2922: 27: 31.843528"
          }
      ]
  }
  </code></pre>
  
  <p>Can someone help me how to make this a valid jsonArray ? Thanks </p>