我正在尝试用Node JS解析JSON对象,当我打印响应的主体时我正确地得到了对象,但是当我试图获得object.subsonic-response时,我我得到了NaN。我已经对Google做过很多研究,但我找不到如何让它发挥作用。
请帮忙!
由于
我的代码:
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);
这是JSON对象:
{ '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]
}
}
}
答案 0 :(得分:2)
代码正由节点解析,如(object.subsonic) - response
NaN
。你想要的是object['subsonic-response']
。