d3.js v5-d3.json在Windows上本地读取文件,但在Linux上不是吗?

时间:2019-01-25 22:47:17

标签: d3.js

我的代码在本地运行良好,尝试将json从Windows转换为unix格式,并且文件被放入war文件中以进行部署-之后,我似乎无法读取该文件(csv文件也发生了同样的问题) ,似乎没有定义就退出Promise-任何建议将不胜感激。

SyntaxError: Unexpected token < in JSON at position 0
sovereignBondsPortlet.js:144 Uncaught (in promise) TypeError: Cannot read property 'objects' of undefined
    at sovereignBondsPortlet.js:144


  var dataset = d3.json("50m_unix.json").then(function(data) {
        return data;
  }).catch(console.log.bind(console));

  var worldjson = dataset.then(function(world) {

    var countries = topojson.feature(world, world.objects.countries).features;

    topo = countries;
    draw(topo);
  });

1 个答案:

答案 0 :(得分:0)

就像@Coderino所说,您可能会遇到某种服务器错误。您可能可以通过Chrome开发者工具获得更多详细信息,这是调试和调试代码的好方法。

  1. 使用chrome打开页面。
  2. 打开Chrome开发工具。有很多方法可以做到这一点。有关更多信息,请参阅Google documentation on it
  3. 单击network标签。
  4. 刷新页面
  5. 单击JSON请求。它的名称以50m_unix.json开头。
  6. 从那里,您可以查看各种信息,包括预览,响应,状态等。