-2

I have a JSON response which I convert to string in javascript by doing

var myObject = JSON.stringify(data);

This prints out the results fine but I need to be able to pull specific data like myObject.route.locationSequence[1] or myObject.route.distance. However neither of those seem to work. Below is my JSON response.

{
    "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
        ]
    }
}
MahoreLee
  • 143
  • 1
  • 3
  • 12
  • 1
    http://jsfiddle.net/L4sj7x2z/ – numbers1311407 Feb 14 '15 at 18:11
  • The confusion seems to be that the "JSON response" has already been converted into an object. Just... don't stringify it, and you can access the data as any normal javascript object. Either that, or you meant to use `JSON.parse`, not `stringify`. – numbers1311407 Feb 14 '15 at 18:17

1 Answers1

0

If that is your JSON response then just dont do

JSON.stringify(data)

Simply use data.route.locationSequence[1]

Working Fiddle

void
  • 36,090
  • 8
  • 62
  • 107