谁能帮我解决这个问题:
我收到意外的 token 错误,我已经验证了我的 json 文件和 JS。但我仍然遇到错误。
HTML
<div class="load"></div>
这是JS
/* Table load */
var uri = 'http://*****.com/TestFiles/';
$.ajax({
url: uri + 'json/banks.json',
dataType: 'jsonp',
success: function(data){
var account = data;
console.log(data);
$.each(account, function(Key, Val) {
var row=$('<div class="row"></div>');
console.log(account);
$.each(Val, function(k, v){
console.log(account);
$('<div class="cell"><p>' + v + '</p></div>').appendTo(row);
});
row.appendTo('.load');
});
}
});
这是json文件
{
"count": 5,
"records": [
{
"name": "Big Guy",
"apy": "0.75",
"earnings": "376.41"
},
{
"name": "URGrant",
"apy": "0.87",
"earnings": "436.89"
},
{
"name": "CheatandGrace",
"apy": "0.01",
"earnings": "5.00"
},
{
"name": "The Onion",
"apy": "0.01",
"earnings": "5.00"
},
{
"name": "Pellet Grant",
"apy": "0.01",
"earnings": "5.00"
}
]
}
任何帮助都会很棒。
最佳答案
您正在尝试加载 JSON:
url: uri + 'json/banks.json',
但是告诉 jQuery 将其解析为 JSONP:
dataType: 'jsonp',
JSONP 不是 JSON。您需要指定 'json'
或更改服务器以响应 JSONP。
JSON:
Content-type: application/json
{ "foo" : "bar" }
JSONP:
Content-type: application/javascript
dynamically_generated_callback_name({ "foo" : "bar" });
(提供 JSONP 时注意 Rosetta Flash exploit)。
关于javascript - JS/JSON 未捕获语法错误 : Unexpected token :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26164843/