title: How to create JSON in android with multiple data
body: <p>I've to create in android like this,</p>
  
  <pre><code>"draft":
   [
    { "firstName": "Glen", "lastName": "McGrath" },
    { "firstName": "Steve", "lastName": "Vaugh" }
   ]
  </code></pre>
  
  <p>How can I create this type of JSON? I've been through some links but not getting correct output.</p>
  
  <p>So far, I've tried this code,</p>
  
  <pre><code>JSONObject newObj = null ;              
                  for(int h=0; h&lt;3; h++)
                  {
                      newObj = new JSONObject();
                      newObj.put("firstName", "" + h);
                      newObj.put("lastName", "" + h);
                  }
  
                  JSONArray postjson = new JSONArray();
                  postjson.put(newObj);
  </code></pre>
  
  <p>But, not getting any output while decoding this json in php file.</p>
  
  <p>Below is my .php file to decode json,</p>
  
  <pre><code>$json = $_SERVER['HTTP_JSON'];
  $json = json_decode($json, true);
  mysql_connect("localhost", "root", "") or die(mysql_error()) ; 
  mysql_select_db("retail_menu") or die(mysql_error()) ; 
      foreach($json as $value)
      {
  
          foreach($value as $value1)
          {
              echo $data1 = $value1['firstName'];
              echo $data2 = $value1['lastName'];
  
              $query = "INSERT INTO `rr_friendid` (friend_id, friend_name) VALUES ('$data1','$data2')";
          var_dump($query);
          mysql_query($query);
      }
  
  }
  </code></pre>
  
  <p>But, I can't see any values store in database. I don't know where I'm wrong, in creating json or while decoding it. How can I create json as the above I mentioned? </p>