I am trying to communicate from Java->JS in Android through the use of JSON. I currently create the JSON like so in Java:
JSONObject latLng = new JSONObject();
latLng.put("lat",20.000);
latLng.put("lon",20.000);
JSONArray jsonArray = new JSONArray();
jsonArray.put(latLng);
JSONObject destination = new JSONObject();
destination.put("destination", jsonArray);
passToJs(destination); //theoretical - method looks slightly different
Then, if I log what has been received in JS(lets call it 'data'), the result is the following:
{
"destination":[
{
"lat":20.000,
"lon":20.000
}
]
}
I am having some problem accessing the individual lat/lon values. I've tried:
data[0]
data[0].lat
data.lat
How do I read and save lat/lon to new variables? BTW, I think my JSON is not so good - is it better to just create a single JSON Object and pass that alone?
Thanks.
data['destination'][0].lat