Code example for JSONObject

Methods: put

     * Create the CompassHeading JSON object to be returned to JavaScript 
     * @return a compass heading 
    private JSONObject getCompassHeading() throws JSONException {
        JSONObject obj = new JSONObject();
        obj.put("magneticHeading", this.getHeading());
        obj.put("trueHeading", this.getHeading());
        // Since the magnetic and true heading are always the same our and accuracy 
        // is defined as the difference between true and magnetic always return zero 
        obj.put("headingAccuracy", 0);
        obj.put("timestamp", this.timeStamp);
        return obj;
Experience pair programming with AI  Get Codota for Java