简体   繁体   中英

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 . I am using d3 and vue with to help the process. When I try and load my data using the d3.json() function and outputting to console I get the error

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. the code looks like this:
import data from '../addressOfJsonFile/db.json';
then you can use data variable you imported as your json object. note that you can name your json imported whatever you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM