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

时间:2020-04-01 04:47:53

标签: d3.js

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

**Uncaught (in promise) Error: 400**

我的代码段如下:

var libxml = require("libxmljs");
var xml =  '<?xml version="1.0" encoding="UTF-8"?>' +
            '<!DOCTYPE root [ <!ENTITY bar SYSTEM "http://localhost/password_BurpSuit.txt"> ]>' +
           '<root>' +
               '<child foo="bar">' +
                   '<grandchild baz="fizbuzz">&bar;</grandchild>' +
               '</child>' +
               '<sibling>with content!</sibling>' +
               '<thai>&bar;</thai>'+
           '</root>';
var options = {
    noent: true,
    dtdload: true
}
var xmlDoc = libxml.parseXml(xml, options);
console.log(xmlDoc);

var gchild = xmlDoc.get('//grandchild');

1 个答案:

答案 0 :(得分:2)

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

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);