[英]Read & parse JSON response from API
I have an API endpoint like this: https://client.systemonesoftware.com/bannink/json/?language=nl我有一个这样的 API 端点: https : //client.systemonesoftware.com/bannink/json/?language=nl
I need to read and parse it into a table with all the information.我需要阅读并将其解析为包含所有信息的表格。 But I get no output when I try to do it with Javascript.
但是当我尝试使用 Javascript 执行此操作时,我没有得到任何输出。
<script>
$.getJSON('https://client.systemonesoftware.com/bannink/json/?language=nl', function(data) {
var json = JSON.parse(data);
alert(json.cached);
alert(json.data[1].id);
});
</script>
This piece of code gives nothing..这段代码什么也没给..
$.getJSON returns JavaScript object so you don't need to parse it, try: $.getJSON返回 JavaScript 对象,因此您不需要解析它,请尝试:
$.getJSON('https://client.systemonesoftware.com/bannink/json/?language=nl', function(json) { console.log(json.data[1].id); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
The success callback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure and parsed using the $.parseJSON() method.
成功回调传递返回的数据,通常是一个 JavaScript 对象或数组,由 JSON 结构定义并使用 $.parseJSON() 方法进行解析。 It is also passed the text status of the response.
它还传递响应的文本状态。
I believe your issue is that the data already comes through parsed:我相信您的问题是数据已经通过解析:
<script>
$.getJSON('https://client.systemonesoftware.com/bannink/json/?language=nl', function(json) {
alert(json.cached);
alert(json.data[1].id);
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.