Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
节点中的JSON Javascript解析问题_Json_Parsing_Node.js_Disqus - Fatal编程技术网

节点中的JSON Javascript解析问题

节点中的JSON Javascript解析问题,json,parsing,node.js,disqus,Json,Parsing,Node.js,Disqus,我从Disqs处得到以下(str),预计是JSON: ({“code”:0,“response:{“username”:“FakeGrimlock”,“about”:“我是一只巨型机器人恐龙。为创业编写代码。吃那些无聊或愚蠢的人。喝咖啡和啤酒。”,“name:“FAKE GRIMLOCK”,“url:”,“profileUrl:”,“emailHash:“07bb07626b48f05c093d70fb69ef8a76”,“avatar:”,“{“permalink:”,“cache:”,“is

我从Disqs处得到以下(str),预计是JSON:

({“code”:0,“response:{“username”:“FakeGrimlock”,“about”:“我是一只巨型机器人恐龙。为创业编写代码。吃那些无聊或愚蠢的人。喝咖啡和啤酒。”,“name:“FAKE GRIMLOCK”,“url:”,“profileUrl:”,“emailHash:“07bb07626b48f05c093d70fb69ef8a76”,“avatar:”,“{“permalink:”,“cache:”,“isanymous:”假,“id”: "4379401"}});

所以我把它修好了

str='[' + str.substr(2, str.length-4) + ']'
这就给了我们:

[{“代码”:0,“回复”:{“用户名”:“FakeGrimlock”,“关于”:“我是巨型机器人恐龙。为创业编写代码。吃那些无聊或愚蠢的人。喝咖啡和啤酒。”,“名称”:“假GRIMLOCK”,“url”:“profileUrl”:“emailHash”:“07bb07626b48f05c093d70fb69ef8a76”,“阿凡达”:“{”permalink:“缓存”:“},“isAnonymous”:false,“id”:“4379401”}}]

…在JSONLINT传递,然后尝试将其放入此处的对象中

var obj=JSON.parse(str);
console.log(obj)显示以下内容:

[{代码:0, 答复: {用户名:'FakeGrimlock', 关于:“我是巨型机器人恐龙。为创业公司编写代码。吃那么无聊或愚蠢的人。喝咖啡和啤酒。”, 名字:“假铁锁”, url:“”, 配置文件URL:“”, emailHash:'07bb07626b48f05c093d70fb69ef8a76', 化身:[对象], isAnonymous:错, id:'4379401'}}]

然后它在这里失败了:

console.log(obj.response[0])// response is undefined. 
在JSONLINT中测试obj输出会显示一个错误,我假设是JSON.Parse删除了“”


无论如何,我无法访问数据。

很简单。您的JSON对象是一个数组(前导“[”)。请尝试以下操作:

obj[0].response

或者先不要用括号括起来…

天哪,我的脑子都炸了。谢谢……我试过obj.response[0]……太基本了。啊!再次感谢,恢复了理智