> So, should I treat my JSON object like a Javascript
> multi-dimensional array?
Seeing as how JavaScript doesn't *have* multi-dimensional arrays, I probably
wouldn't put it exactly that way. :-)
But you definitely have the right idea. JSON is simply a text representation
of JavaScript objects, arrays, or other JavaScript types. In other words,
JSON *is* JavaScript code. So, once you "eval" it and have a reference to
the eval'ed data, treat it exactly as you would any other JavaScript object
or array - whatever the data type is.
Pure JavaScript:
var foo = { a:1, b:2 };
alert( foo.a ); // "1"
Or the same thing with quotes:
var foo = { "a":1, "b":2 };
alert( foo.a ); // "1"
JSON+JavaScript
var jsonText = '{ "a":1, "b":2 }';
// The '(' and ')' are required for syntactic reasons
var jsonObject = eval( '(' + jsonText + ')' );
alert( jsonObject.a ); // "1"
Or alternatively - does the same thing:
var jsonText = '{ "a":1, "b":2 }';
eval( 'var jsonObject = ' + jsonText );
alert( jsonObject.a ); // "1"
In the case of $.getJSON, the "eval" has already been done for you, and the
resulting jsonObject is passed to your callback function.
-Mike