Reputation: 300
At the moment I'm using JSON to call words for my games I'm making but I wondering if I could do it with multiple images without a massive length of code for each round. Here is what I got so far but it's complaining about the duplicate "url". Or would I be better of using an array
Thanks
{
"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" }
]
}
Upvotes: 0
Views: 1453
Reputation: 32212
Since it appears you're aware of the use of arrays in JSON already (you have two entries within your images
array already), how about storing each set of urls in an array:
{
"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"
]
}
]
}
Upvotes: 2