node.js - cannot parse json (body) object in nodejs -


i new node.js, can in below issue.

i calling rest api , returning response body wiht json object. not able parse properly.

i tried body.destination_addresses[0] retrieve value doesn't work.

here code sample

 var parsedjson=json.parse(body);  body.destination_addresses[0]; 

with parsing able retrieve value of body.destination_addresses[0] failed retrieve "parsedjson.rows.elements[1].distance.text" value.

how can retrieve distance value json.

sample json

body: {    "destination_addresses" : [       "458-500 st johns pl, brooklyn, ny 11238, usa",       "395 4th ave, brooklyn, ny 11215, usa"       ],    "origin_addresses" : [ "127 tech pl, brooklyn, ny 11201, usa" ],    "rows" : [       {          "elements" : [             {                "distance" : {                   "text" : "2.3 mi",                   "value" : 3624                },                "duration" : {                   "text" : "15 mins",                   "value" : 899                },                "status" : "ok"             }   ]       }    ],    "status" : "ok" } 

your elements array has 1 item can't @ index 1

as per sample try code

body.rows[0].elements[0].distance.text

you need clear basic javascript , how use array


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -