Programatically create a complex JSONArray in Android? : I have been struggling trying to make this work properly. From what I have read the following example is a JSONArray. I need to be able to dynamically create such an array problematically within my Android code, so that it can output this array to a web service. I am most confused about adding the top "header" information and the nested "Position" JSONObject as the last property. I know how a basic JSONObject is created, as well as a basic JSONArray, but this combined one is really throwing me off. Any help would be much appreciated. This is the example I was given that I need to try to create:

    {
        "source": "REMOTE",
        "msgType": "event",
        "properties": [
            {
                "IMEI": {
                    "string": "1234567890"
                }
            },
            {
                "My Time": {
                    "string": "5/4/2016 12:00:00"
                }
            },
            {
                "Position": {
                    "geographicPosition": {
                        "latitude": 34.89767579999999,
                        "longitude": -72.03648269999997
                    }
                }
            }
        ]
    }