我想获取一个外部 json 文件(locations.json)并将内容加载到一个变量中。然后我想使用这里提供的信息来使用这个变量:http: //www.json.org/js.html
我在尝试将外部 json 加载到变量时遇到了很多麻烦。我已经看过这个(将 json 加载到变量中)页面很多,但实际上并没有填充变量。稍后显示变量的内容时,它似乎是空的。
$("#testContain").html("<p>" + json + "</p>");
使用最后一个链接中列出的方法,这将显示“未定义”。
我正在使用的 json 文件如下所示:
[{"id":"1","locname":"Dunstable Downs","lat":"51.8646","lng":"-0.536957","address":"Chiltern Gateway Centre","address2":"","city":"","state":"England","postal":"","phone":"","web":"http:\/\/www.nationaltrust.org.uk\/main\/w-dunstabledownscountrysidecentrewhipsnadeestate","hours1":"","hours2":"","hours3":""},
{"id":"2","locname":"West Delta Park","lat":"45.5974","lng":"-122.688","address":"N Broadacre St and N Expo Rd, Portland","address2":"","city":"","state":"OR","postal":"","phone":"","web":"http:\/\/en.wikipedia.org\/wiki\/Delta_Park","hours1":"","hours2":"","hours3":""}]
有人有什么建议吗?