我在json中有一个数组,由其他三个数组组成。这三个数组中的一个还有另一个嵌套在其中的数组,该数组中嵌套了第三个数组:
{
"items": [
{location: "Tiberius' Palace",
starting_line: 0,
line_text: "I command sylyns, in þe peyn of forfetur,",
duration: 1,
characters: {first_character:
{character: "Emperor", color: "660066"}
}
}
],
"directions": [],
"locations": []
}
我以非常标准的方式将这个json送入d3:
d3.json("MM_chart_test.json", function(error, json)
然后调用三个数组中的每一个:
var items = json.items;
var locations = json.locations;
var directions = json.stage_directions;
我遇到的问题是,使这些变量声明会导致items变量丢弃比字符声明更深的东西,因此json看起来像这样:
{location: "Tiberius' Palace",
starting_line: 0,
line_text: "I command sylyns, in þe peyn of forfetur,",
duration: 1,
characters: {first_character:
null}
}
除了变量声明之外我没有做过任何事情,其他两个数组都运行正常。对我来说很明显,问题在于声明变量,但我想知道最好的方法是什么,而不会丢失那两个深度的信息。谢谢。
答案 0 :(得分:0)
在属性名称周围添加引号。正如Sebastian Lorenzo所述,它是无效的JSON。
{
"location":"Tiberius' Palace",
"starting_line":0,
"line_text":"I command sylyns, in þe peyn of forfetur,",
"duration":1,
"characters":{
"first_character":null
}
}