【发布时间】:2014-10-13 16:23:47
【问题描述】:
在您将此问题标记为重复之前,请阅读它:) 我遇到的问题是我使用的 JSON 文件以数组开头,所以当我尝试解析它时,我得到了这个:
Cannot read property '0' of undefined
这是我要解析的 json 文件:
http://data.police.uk/api/crimes-at-location?date=2014-1&lat=52.629729&lng=-1.131592
这是我正在使用的代码:
var link = "http://data.police.uk/api/crimes-at-location?date=2014-1&lat=52.629729&lng=-1.131592";
$.getJSON(link, function (json) {
// Set the variables from the results array
var cat = json.data[0].catageroy;
$("#location").replaceWith('Category : ', cat);
});
求助!!!
谢谢
【问题讨论】:
-
var cat = json[0].catageroy;
标签: javascript jquery json parsing