【发布时间】:2013-05-03 07:01:53
【问题描述】:
bfunc({
"query": {
"count": 1,
"created": "2013-05-03T06:20:01Z",
"lang": "en-US",
"diagnostics": {
"publiclyCallable": "true",
"cache": {
"execution-start-time": "32",
"execution-stop-time": "32",
"execution-time": "0",
"method": "GET",
"type": "MEMCACHED",
"content": "http://www.vtualerts.com/robots.txt"
});
这是我需要使用 javascript 和 jQuery 解析的 JSON 数据。我试着这样做......
<div id="placeholder"></div>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$.getJSON('myjson.json', function(data) {
var output= data.cbfunc.query.count+ "" + data.cbfunc.query.created;
document.getElementById("placeholder").innerHTML=output;
});
但我收到一个错误
XMLHttpRequest 无法加载 file:///home/shivratna/Desktop/myjson.json。 Access-Control-Allow-Origin 不允许 Origin null。
请帮忙。
衷心感谢
【问题讨论】:
-
尝试放置 alert("data :"+JSON.stringify(data));也许您正在获取数据。通过放置此行进行验证。
-
bfunc(...)不是有效的 JSON。它甚至不是有效的 JSONP。 -
它甚至不是有效的 JSONP。你缺少右括号。
-
使用 alert() 进行测试,但您似乎有 4 个“{”但只有 1 个“}”
-
@EmRa228
console.log()更好
标签: javascript jquery json parsing