antonpug antonpug - 6 months ago 9
JSON Question

What are the differences between using JSON arrays vs JSON objects?

What are the difference and advantages of using JSON arrays:

{
thing:[
{ },
{ }
]
}


versus JSON objects:

{
thing:{
{ },
{ }
}
}

Answer

Not to sound like a smart ass, but well...

The difference between an array and an object.

Objects are set up using a key and value like...

person.age = 15;

If the key value is a variable, then one could access it like...

var key = "age";
alert(person[key]);

Arrays use an integer[1] index and take a value.

player[1].score += 1000;

[1] Yes, I know ... in Javascript the integer index is really turned into a string behind the scenes. Ignore that. Think of arrays taking an integer value ESPECIALLY when you think of JSON.