Reputation: 9
I'm trying to parse a JSON object with Node JS, when i'm printing the body of the response I'm getting the object correctly, but when I'm trying to get object.subsonic-response, I'm getting NaN. I've done a lot of research on Google, but I can't find how to get this to work.
Please help !
Thanks
My code:
var request = require('request');
var options = {
url : host + view + logginParameters + actionParameters,
headers: {
'User-Agent': 'request'
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var object = JSON.parse(body);
console.log(object.subsonic-response);
}
}
request(options, callback);
Here is the JSON object:
{ 'subsonic-response':
{ status: 'ok',
version: '1.15.0',
playlist:
{ id: '39',
name: 'Smoothie !',
comment: '',
owner: 'william',
public: true,
songCount: 24,
duration: 5392,
created: '2015-11-19T17:08:02.874Z',
changed: '2016-03-27T04:10:19.753Z',
coverArt: 'pl-39',
entry: [Object]
}
}
}
Upvotes: 0
Views: 261
Reputation: 143
The code is being parsed by node like this (object.subsonic) - response
which is NaN
. What you want is object['subsonic-response']
.
Upvotes: 2