d3.json()无法执行.不断收到错误:400

问题描述:

我正在创建一个虚拟JSON值,并试图显示它们,但问题是我不断收到此错误:

I'm creating a dummy JSON value and is trying to show them but the problem is i keep getting this error:

我的代码段如下:

var jsonData = '[{"id":"31370100","machine_name":"GUMACA BRANCH CAM","machine_type":"CAM","operation_start":"05:04:33","operation_end":"09:04:33"}]'

d3.json(jsonData).then((data)=>{
  console.log(data);
});

d3.json将URL作为参数.由于已经有了JSON,您可能只需要JSON.parse(),并且在此实例中无需使用d3.因此您的代码应类似于:

d3.json takes a URL as the parameter. As you have the JSON already, you probably just need JSON.parse(), and there is no need to use d3 in this instance. So your code would look something like:

var jsonData = '[{"id":"31370100","machine_name":"GUMACA BRANCH CAM","machine_type":"CAM","operation_start":"05:04:33","operation_end":"09:04:33"}]'

let data = JSON.parse(jsonData);
console.log(data);