Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  108] [ 2]  / answers: 1 / hits: 26755  / 12 Years ago, sat, october 6, 2012, 12:00:00

Despite much googling and hair-pulling, I can't for the life of me articulate the difference between json, objects, and arrays (in javascript). Below is how I've been using 2-dimensional data containers (afraid to use the words array, object, or json here). Please tell me what these two examples are?



//first example:
[
{record_id:1,name:Frank},
{record_id:2,name:Sally}
]

//second example:
{
countries:
[
{id:1,name:Canada},
{id:2,name:Mexico}
],
states:
[
id:1,name:Maine},
{id:2,name:Alaska}
]
}

More From » json

 Answers
69

JSON is a representation of the data structure, it's not an object or an array.



[1,2,3]


is an array.



{foo:bar}


is an object.



In your example,



[
{record_id:1,name:Frank},
{record_id:2,name:Sally}
]


Is an array of objects.



{
countries:
[
{id:1,name:Canada},
{id:2,name:Mexico}
],
states:
[
{id:1,name:Maine},
{id:2,name:Alaska}
]
}


Is an object containing other arrays and objects inside of it.


[#82720] Thursday, October 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daveon

Total Points: 749
Total Questions: 108
Total Answers: 87

Location: Malaysia
Member since Wed, May 11, 2022
2 Years ago
;