title: How to Create a JSON Object and Array of Objects?
body: <p>I am wanting to get data from a phone (geoLocation data) and put that into a JSON Object and send that over a network to a database to be stored. I am unsure how to create this object and if it should be an array of objects. Also, how do I setup the object to receive new information as it updates to send to the server? Here is the code I currently have. I am using eclipse, phonegap, javascript and JSON.</p>
  
  <pre><code>var JSONID = 0;
  
      // Create a JSON Object Array
      geoLocJSON ();
  
      /* This is what I want my Object to look like.
      [   
          {
          "id" : 0,
          "geoLoc" : {
                          "Lat" : "",
                          "Long" : ""
                      },
          "direction" : {
                          "Alt" : "",
                          "Head" : "",
                          "Speed" : ""
                         },
          "Time" : ""
          };
      ]
      */
  
  // onSuccess Geolocation
      function onSuccess(position){
          // Testing for data
          var element = document.getElementById('geolocation');
          element.innerHTML = 
          'Latitude: ' + position.coords.latitude + '&lt;br /&gt;' +
          'Longitude: ' + position.coords.longitude + '&lt;br /&gt;' +
          'Altitude: ' + position.coords.altitude + '&lt;br /&gt;' +
          'Heading: ' + position.coords.heading + '&lt;br /&gt;' +
          'Speed: ' + position.coords.speed + '&lt;br /&gt;' +
          'Timestamp: ' + new Date(position.timestamp) + '&lt;br /&gt;' +
          '&lt;hr /&gt;' + element.innerHTML;
  
          // Puts into JSON Object
          geoLocJSON.id = JSONID;
          geoLocJSON.geoLoc.Lat = position.coords.latitude;
          geoLocJSON.geoLoc.Long = position.coords.longitude;
          geoLocJSON.direction.Alt = position.coords.altitude;
          geoLocJSON.direction.Head = position.coords.heading;
          geoLocJSON.direction.Speed = position.coords.speed;
          geoLocJSON.Time = new Date(position.timestamp);
  
          // Increments the JSONID
          JSONID++;
      }
  </code></pre>
  
  <p>This will then be posted to the server after 1 minute of collecting data and the JSON Object will be erased UNLESS the POST is unsuccessful, then the object will be stored locally to the device and posted later when a network is available again.</p>
  
  <p>Thank you for your help.</p>