[英]Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 using vuejs
I am trying to create a treemap based on data from a .json
.我正在尝试根据来自
.json
的数据创建树形图。 I am using d3 and vue with to help the process.我正在使用 d3 和 vue 来帮助这个过程。 When I try and load my data using the
d3.json()
function and outputting to console I get the error当我尝试使用
d3.json()
function 加载数据并输出到控制台时出现错误
Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
d3.json('./warehouses').then(function(error,data) {
data = data.concat(json)
render(data)
console.log(data)
})
if you want to load a json file, you should import it.如果要加载 json 文件,则应将其导入。 the code looks like this:
代码如下所示:
import data from '../addressOfJsonFile/db.json';
then you can use data variable you imported as your json object.然后您可以使用您作为 json object 导入的数据变量。 note that you can name your json imported whatever you want.
请注意,您可以随意命名您的 json 导入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.