admin管理员组文章数量:1279145
I'm having trouble reading properties from JSON within NodeJS.
Feels like an obvious mistake I may be making..
The JSON is from this endpoint;
.js
My code:
var request = require('request');
request(".js", function (err, res, json) {
JSON.parse(json);
console.log(json["1"]["artist"]); // undefined
});
~
I'm having trouble reading properties from JSON within NodeJS.
Feels like an obvious mistake I may be making..
The JSON is from this endpoint;
http://hypem./playlist/history/faisdotal/json/1/data.js
My code:
var request = require('request');
request("http://hypem./playlist/history/faisdotal/json/1/data.js", function (err, res, json) {
JSON.parse(json);
console.log(json["1"]["artist"]); // undefined
});
~
Share Improve this question asked Jan 24, 2012 at 0:22 faiizowfaiizow 851 gold badge1 silver badge6 bronze badges2 Answers
Reset to default 5You need to store the returned value of JSON.parse:
json = JSON.parse(json);
console.log(json["1"]["artist"]);
I think you want:
json = JSON.parse(json);
It won't (and can't) simply update the value of the parameter. The .parse()
routine returns the value parsed from the string you pass it.
JavaScript is purely call-by-value, so there's really no way it could possibly work the way your code is written.
本文标签: javascriptReading JSON properties in NodeJSStack Overflow
版权声明:本文标题:javascript - Reading JSON properties in NodeJS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741285294a2370235.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论