当我在删除ID后导入json数据时,我的导入功能可以正常工作。但是,如果我使用自己的ID导入数据,则控制台会显示数据未定义。
[
{
"data" : "abc",
"parent" : null,
"type" : "Organization",
"parentType" : null,
"API" : "",
"value" : "abc",
"filename" : "uploads.wsdl",
"company" : "comapany"
},
{
"data" : "def",
"parent" : "abc",
"type" : "Department",
"parentType" : "Organization",
"API" : "",
"value" : "def",
"filename" : "uploads.wsdl",
"company" : "company"
}
]
d3.json("marvel.json", function(error, mydata) {
console.log(mydata)
});
上面的代码工作正常。
[
{
"_id" : ObjectId("5d2d862a68a6bc22a9e99046"),
"data" : "abc",
"parent" : null,
"type" : "Organization",
"parentType" : null,
"API" : "",
"value" : "abc",
"filename" : "uploads.wsdl",
"company" : "company"
},
{
"_id" : ObjectId("5d2d862a68a6bc22a9e99047"),
"data" : "def",
"parent" : "abc",
"type" : "Department",
"parentType" : "Organization",
"API" : "",
"value" : "def",
"filename" : "uploads.wsdl",
"company" : "comapny"
}
]
d3.json("marvel.json", function(error, mydata) {
console.log(mydata)
});
在此代码中,mydata未定义
答案 0 :(得分:-1)
此:
{"_id" : ObjectId("5d2d862a68a6bc22a9e99047")}
无效的JSON,函数调用或对象初始化不是JSON规范的一部分,失败将在任何理智的JSON解析器下失败。