I have a problem with getting some JSON fields in NodeJS. Here is my JSON structure:
{
"header":
{
"file1":0,
"file2":1,
"subfiles":{
"subfile1":"true",
"subfile2":"true",
}
},
"response":
{
"number":678,
"start":0,
"docs":[
{
"id":"d3f3d",
"code":"l876s",
"country_name":"United States",
"city":"LA"
},
{
"id":"d2f2d",
"code":"2343g",
"country_name":"UK",
"city":"London"
}
]
}
}
How to access to specific fields (id, city or country_name) in structure like this? I'm trying something in NodeJS, but I cannot get specific fields.
request('http://url.com', function (error, res, body) {
if (!error && res.statusCode == 200) {
console.log(body)
}
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(){
var urlResponse = JSON.parse(body);
console.log("Got a response: ", urlResponse.response.docs.city);
});
});