user3534084 user3534084 - 1 year ago 153
Javascript Question


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 !


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);

request(options, callback);

Here is the JSON object:

{ 'subsonic-response':
{ status: 'ok',
version: '1.15.0',
{ 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] } } }

Answer Source

The code is being parsed by node like this (object.subsonic) - response which is NaN. What you want is object['subsonic-response'].

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download