【问题标题】:Manipulating / Using JSON created on the website操作/使用网站上创建的 JSON
【发布时间】:2020-04-01 00:48:25
【问题描述】:

我的网站上有这个 Json 结果,可以在我的 d3.js 上使用。问题是我无法操纵它或任何使用它的方法。

这是在上图中抛出 JSON 结果的控制器:

我尝试了 d3.json() 函数,但没有成功。它不会在 console.log() 上显示任何输入。

var url = "/queries/31370100";
d3.json(url, function(data) {
  console.log(data);
});

我也尝试过使用 Ajax,但它也不起作用。

【问题讨论】:

标签: json spring-boot


【解决方案1】:

您使用的是哪个版本的 d3.js?您还可以尝试使用新的 d3 Promise 语法和一些捕获来查看它是否是内容或请求位置的问题 - 这样的事情应该会有所帮助:

d3.json(YOUR_FULL_URL).then(function (data) {

    if (typeof data === 'undefined' || data === null) {
        console.error("Failed to retreive the data");
    } else {
        console.log(data);
    }
}).catch(function (error) {
    console.error("Failed to retreive the data or there was an error parsing the response: " + error);
});  

有关更多信息,这是对 Promise 语法及其为何有用的有用解释:https://talk.observablehq.com/t/overcoming-difficulties-with-json-data-loading-or-another-mistake/688/2

【讨论】:

  • 嗨,它有效!但如果我调用 data.id,它只会显示“未定义”
  • 查看您提供屏幕截图的 JSON sn-p 中的参数名称。他们看起来有点滑稽。我认为“id:”应该是“id”:“the_id_value”。
猜你喜欢
  • 2011-12-24
  • 2023-03-28
  • 1970-01-01
  • 2015-08-20
  • 2011-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多