This is my json:
{
"xuid":****************,
"state":"Online",
"devices":[
{
"type":"XboxOne",
"titles":[
{
"id":750323071,
"name":"Accueil",
"placement":"Background",
"state":"Active",
"lastModified":"2018-02-23T17:09:38.4018406Z"
},
{
"id":1145574011,
"activity":{
"richPresence":"Dans un salon priv\u00e9"
},
"name":"Titanfall\u2122 2",
"placement":"Full",
"state":"Active",
"lastModified":"2018-02-23T17:09:38.4018406Z"
}
]
}
]
}
I would like to recover the value: devices->titles->1->activity->richPresence
This is my code with nodeJs:
function (error, response, body) {
if (!error && response.statusCode === 200) {
var xbJson = JSON.parse(body);
console.log(xbJson.devices.titles[1]['name'])
}
}
My error:
TypeError: Cannot read property '1' of undefined
at Request._callback (/home/atmoner/Bureau/xboxlive/test.js:16:40)
at Request.self.callback (/home/atmoner/Bureau/xboxlive/node_modules/request/request.js:186:22)
at emitTwo (events.js:125:13)
at Request.emit (events.js:213:7)
at Request.<anonymous> (/home/atmoner/Bureau/xboxlive/node_modules/request/request.js:1163:10)
at emitOne (events.js:115:13)
at Request.emit (events.js:210:7)
at IncomingMessage.<anonymous> (/home/atmoner/Bureau/xboxlive/node_modules/request/request.js:1085:12)
at Object.onceWrapper (events.js:312:19)
at emitNone (events.js:110:20)
I guess the problem comes from the array in a json and I can not move further.
It may sound simple but I need some help.
Thank you!...
console.log(xbJson.devices[0].titles[1]['name'])asdevicesis an array?