這是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