SyntaxError:JSON解析错误:意外的标识符" object" (匿名功能) [英] SyntaxError: JSON Parse error: Unexpected identifier "object" (anonymous function)
本文介绍了SyntaxError:JSON解析错误:意外的标识符" object" (匿名功能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不明白解析文件时出了什么问题:
I do not understand what went wrong when parsing file:
{ "t": -9.30, "p": 728.11, "h": 87.10 }
javascript代码:
javascript code:
<script type="text/javascript">
function check() {
$.get("http://....file.json", function(response, status, xhr) {
if (status == "success") {
var json = JSON.parse(response);
$("#temp").html(json.t + "°");
$("#pressure").html(json.p + " mm hg");
}
if (status == "error") {
$("#temp").html("error");
}
});
}
我收到错误:
SyntaxError: JSON Parse error: Unexpected identifier "object"
推荐答案
很可能你的响应
已经是一个JavaScript对象,不需要解析它。
Most probably your response
is already a JavaScript object and it not required to be parsed.
删除行 var json = JSON.parse(response);
,您的代码应该有效。
Remove the line var json = JSON.parse(response);
and your code should work.
这篇关于SyntaxError:JSON解析错误:意外的标识符" object" (匿名功能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文