[英]How can I navigate JSON nested file using d3.js?
Thank you for help in advance . 预先感谢您的帮助。 here is my problem , I'm finding trouble to explore a json nested file and try .
这是我的问题,我在探索json嵌套文件并尝试时遇到了麻烦。 Here is my json file
这是我的json文件
{"Id":466,"Name":"korea",
"Occurrences":
[
{"OccurrenceDate":"\/Date(1398207600000+0100)\/","OccurrenceFrequency":27},
{"OccurrenceDate":"\/Date(1398726000000+0100)\/","OccurrenceFrequency":1},
{"OccurrenceDate":"\/Date(1398898800000+0100)\/","OccurrenceFrequency":4},
{"OccurrenceDate":"\/Date(1399071600000+0100)\/","OccurrenceFrequency":303}]}
This is my code Javascript code: 这是我的代码Javascript代码:
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
d3.json("data2.json", function(error, data) {
data.forEach(function(d) {
console.log(d.Id)
console.log(d.Name)
console.log(d.Occurrence.OccurrenceFrequency)
console.log(d.Occurrence.OccurrenceDate)})
return d;
});
});
</script>
Really looking for a help 真的在寻找帮助
Give this a try. 试试看。 Given your format, which is an object, you can't use forEach on it, but it doesn't appear that you need to.
给定格式(即对象),就不能在其上使用forEach,但似乎并不需要。
d3.json("data2.json", function(error, data) {
console.log(data.Id)
console.log(data.Name)
data.Occurences.forEach(function(d) {
console.log(d.OccurrenceFrequency)
console.log(d.OccurrenceDate)})
return d;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.