我正在尝试存储一个"多维数组"在javaScript读取的json文件中,实际上只是一个包含多个数组的数组。这可能吗?如果是这样的话?我尝试用与javascipt相同的方式编写它,这不会起作用,但可能代码还有其他问题。这是我的JSON文件:
{
"HTML": [['button','level1Button','position:absolute; top:100px; left:200px;','LEVEL I','loadLevel(1)',false,false],['a','howtoplayhref','position:absolute; top:100px; left:100px;','how to play',false,false,'howtoplay.html']],
"levelObjects": "StillEmptyForNow"
}
答案 0 :(得分:1)
MinusFour是正确的,JSON需要双引号:
var a = {"myarr": [["a1", "b1"], ["a2", "b2"]]}
a["myarr"][1][1]
> "b2"
var a = {"HTML": [["button","level1Button","position:absolute; top:100px; left:200px;","LEVEL I","loadLevel(1)",false,false],["a","howtoplayhref","position:absolute; top:100px; left:100px;","how to play",false,false,"howtoplay.html"]]}
a["HTML"][1][1]
> "howtoplayhref"
答案 1 :(得分:0)
我将你的JSON粘贴到控制台并将强制性的var x=
放在它前面,它运行得很好。然后使用JSON.stringify(x,null,' ')
获得以下内容:
var x=
{
"HTML": [
[
"button",
"level1Button",
"position:absolute; top:100px; left:200px;",
"LEVEL I",
"loadLevel(1)",
false,
false
],
[
"a",
"howtoplayhref",
"position:absolute; top:100px; left:100px;",
"how to play",
false,
false,
"howtoplay.html"
]
],
"levelObjects": "StillEmptyForNow"
}
JSONtext.innerHTML=JSON.stringify(x,null,' ')

<pre id='JSONtext'></pre>
&#13;