将json加载到javascript中

将json加载到javascript中,javascript,json,Javascript,Json,我有一个json html链接,如下所示 www.pretendJsonLink.com/getData 我收到的数据如下: {"Items":[{"date":1498850140373,"displayId":"003","sentId":"121213", "customer":"ME"}, {"date":1452870140571,"displayId":"007","sentId":"152713", "customer":"YOU"}],"Count":2,"ScannedCou

我有一个json html链接,如下所示

www.pretendJsonLink.com/getData
我收到的数据如下:

{"Items":[{"date":1498850140373,"displayId":"003","sentId":"121213",
"customer":"ME"}, {"date":1452870140571,"displayId":"007","sentId":"152713",
"customer":"YOU"}],"Count":2,"ScannedCount":2}
我需要将其加载到一个js文件中,这样我就可以根据需要在id=”“标记的html文件中调用它们

比如Items.date和Items.customer之类的

任何帮助都会很好,我知道这应该是一项简单的任务,但我也可以转发我的搜索历史:)我一直在寻找有效的解决方案,但似乎找不到任何适合我需要的解决方案

使用
JSON.parse()
函数。这是您可以使用的

的链接。我找到了一个很好的例子,包括(简化的),如下:


JSON.parse您的代码是什么样子的?您使用的是
XMLHttpRequest
(又称AJAX)吗?如果是这样的话,为什么不在回调中设置一个变量,然后处理它呢?你能再解释一下你问题的这一部分吗,“我收到的数据如下”?你是怎么收到的?您当前必须接收的代码是什么?我基本上处于开始阶段,对于从链接解析json数据而言,没有任何代码明智。
var req = new XMLHttpRequest();
req.open('GET', 'www.pretendJsonLink.com/getData');

req.onload = function() {
    if (req.status == 200) {
      // do what you want, here, with the req.response
      // take a look at the object that gets returned, you may need
      // to call JSON.parse(), etc.
      console.log('success', req.response);
    } else {
      console.log('error', req.statusText);
    }
};

// Handle network errors
req.onerror = function() {
    console.log("Network Error");
};

// Make the request
req.send();