目前我正在使用JSON为我正在制作的游戏调用单词,但我想知道是否可以使用多个图像来执行此操作而不需要每轮的大量代码。这是我到目前为止所得到的,但它抱怨重复" url"。或者我会更好地使用数组
由于
{
"images": [
{"imageID" : "game1", "url" : "gameImages/img1.jpg", "url" : "gameImages/img2.jpg",
"url" : "gameImages/img3.jpg", "url" : "gameImages/img4.jpg" }
{"imageID" : "game2", "url" : "gameImages/img5.jpg", "url" : "gameImages/img6.jpg",
"url" : "gameImages/img7.jpg", "url" : "gameImages/img8.jpg" }
]
}
答案 0 :(得分:2)
由于您似乎已经意识到已经在JSON中使用了数组(您的images
数组中已经有两个条目),如何将每组URL存储在一个数组中:
{
"images": [
{
"imageID": "game1",
"urls": [
"gameImages/img1.jpg",
"gameImages/img2.jpg",
"gameImages/img3.jpg",
"gameImages/img4.jpg"
]
},
{
"imageID": "game2",
"urls": [
"gameImages/img5.jpg",
"gameImages/img6.jpg",
"gameImages/img7.jpg",
"gameImages/img8.jpg"
]
}
]
}