When working with a JSON response in JavaScript, I use the following code to convert it to a string:
var myObject = JSON.stringify(data);
Although this code successfully prints out the results, I am having trouble extracting specific data such as myObject.route.locationSequence[1] or myObject.route.distance. Unfortunately, neither of these seem to work as expected. The JSON response I am working with is shown below.
{
"route": {
"hasTollRoad": false,
"computedWaypoints": [],
"fuelUsed": 5.67,
"hasUnpaved": false,
"hasHighway": true,
"realTime": -1,
"boundingBox": {
"ul": {
"lng": -77.863792,
"lat": 40.811218
},
"lr": {
"lng": -76.30574,
"lat": 39.962482
}
},
"distance": 142.909,
"time": 9872,
"locationSequence": [
0,
2,
1,
3
]
}
}