D3.js - 对JSON文件的令人费解的解释?

时间:2014-03-11 15:22:10

标签: javascript json d3.js

我正在使用的JSON文件的解释方式与我预期的不同。

外部JSON文件:

{"organizations":[{"member":{"source":"TCAN","target":"Resilient Toronto","category-source":"organization","category-target":"organization"}},{"member":{"source":"City of Toronto","target":"","category-source":"organization","category-target":""}},{"member":{"source":"Resilient Toronto","target":"City of Toronto","category-source":"organization","category-target":"organization"}},{"member":{"source":"Rita Bijons","target":"ZCO","category-source":"volunteer","category-target":"organization"}},{"member":{"source":"Rita Bijons","target":"Green 13","category-source":"volunteer","category-target":"community group"}},{"member":{"source":"Green 13","target":"TCAN","category-source":"community group","category-target":"organization"}},{"member":{"source":"ZCO","target":"TCAN","category-source":"organization","category-target":"organization"}}]}

我不明白为什么源字段被解释为对象而category-source不被解释为对象。是因为这个名字吗?为什么源对象中有类别字段?名字未定义?显然我缺少一些基本的理解。有没有记录在哪里?

Console Log output

2 个答案:

答案 0 :(得分:1)

我刚用PrettyPrint测试了你的JSON,并且格式正确。因此,问题在于您使用的软件/代码来显示(格式化)JSON数据。

enter image description here

答案 1 :(得分:0)

看起来您正在通过force layout运行数据,并且它与您的媒体资源名称“来源”相冲突。具体来说,force.links调用将通过添加“source”和“target”属性来更改数据,这些属性看起来就像您引用的结构。

检查您是否在任何时候将数据传递给force.links。