这是XMLHttpRequest对象。当我把它放在cosole.log
它提供了以下回应:JSON解析问题与AJAX
console.log(this.responseText);
"[
{
"url": "https://api.github.com/gists/c7c0df592e99c0c34b99",
"forks_url": "https://api.github.com/gists/c7c0df592e99c0c34b99/forks",
"commits_url": "https://api.github.com/gists/c7c0df592e99c0c34b99/commits",
"id": "c7c0df592e99c0c34b99",
"git_pull_url": "https://gist.github.com/c7c0df592e99c0c34b99.git",
"git_push_url": "https://gist.github.com/c7c0df592e99c0c34b99.git",
"html_url": "https://gist.github.com/c7c0df592e99c0c34b99",
"files": {
"config.json": {
"filename": "config.json",
"type": "application/json",
"language": "JSON",
"raw_url": "https://gist.githubusercontent.com/anonymous/c7c0df592e99c0c34b99/raw/70489beaa4953f89fc8848195371da6eca76164c/config.json",
"size": 17911
}
},
"public": true,
"created_at": "2015-04-26T20:34:11Z",
"updated_at": "2015-04-26T20:34:11Z",
"description": "Bootstrap Customizer Config",
"comments": 0,
"user": null,
"comments_url": "h"[…]
但是当我尝试使用就可以了JSON.parse
它给了我一个错误:SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
。
要旨= JSON.parse(this.reponseText)
IM应该是使用此API https://developer.github.com/v3/gists/和它应该根据该文档
在上述数据,是由返回的返回有效的JSON网站无效JSON?或者我应该使用JSON.parse
以外的其他功能?或者发生了什么?请帮忙。
全引擎收录在这里:http://pastebin.com/BWttNtXP
这不是有效的JSON是为什么... ...这怎么被生产?我们可以看到这些代码吗? –
您需要将开始的引号替换为单引号,因为您的内引号是双引号。 –
@ChavdarSlavov - 这可能是JSON复制/粘贴的查看器的人造物。 – Quentin