我不明白解析文件时出了什么问题:
{ "t": -9.30, "p": 728.11, "h": 87.10 }
javascript代码:
<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 对象,不需要对其进行解析。
删除 var json = JSON.parse(response);
行,您的代码应该可以工作。
关于javascript - 语法错误 : JSON Parse error: Unexpected identifier "object" (anonymous function),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20660399/