Good evening, guys!
I'm writing a NodeJS that accesses a URL that contains a JSON in that JSON the keys contain special "-" character that is causing error in my application what would be the correct way to access them?
Example Error:
var playing = ('#Touching Now:' + parsedRadio.data.current-music.song);
ReferenceError: music is not defined
JSON Example:
data: {
current-music: {
singer: "NOME_BANDA",
song: "NOME_MÚSICA"
}
}
Example Code:
const request = require('request');
request('http://myplayer.myradio.com.br/tocando.php', function (error, response, body) {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
var parsedRadio = JSON.parse(body);
var tocando = ('#TocandoAgora: ' + parsedRadio.data.current-music.song);
console.log(tocando);
});
I have tried the following ways and I did not succeed.
parsedRadio.data.[current-music].song
parsedRadio.data.['current-music'].song
parsedRadio.data.'current-music'.song
parsedRadio.data.currentmusic.song
parsedRadio.data.{current-music}.song
Please forgive me if this is a basic bug, I'm still learning NodeJs. Thank you all.