I have a json file with contents like this:
{
\"aaa\":{
\"status\":\"available\",
\"classkey\":\"dotnet\"
},
\"bbb\":{
Use the for...in construct, and then use array syntax. Here is an example.
for (var key in xxx) {
document.write(xxx[key]);
}
You don't have an array, you have an object. As such you cannot expect the keys to be in the same order on all systems. Iterate the object as objects are expected to be iterated, that is, over the keys you are given.
Maybe this can solve your problem.
Using jQuery you can convert your JSon to Array and access it by index.
var data = $.parseJSON(msg.d ? msg.d : msg);
alert(data[1].status)
For the sake of providing an answer to the question title, here is the array structure that would serve the original purpose:
[
{
"status":"available",
"classkey":"dotnet"
},
{
"ccc":{
"com":"available",
"net":"available",
"info":"available",
"org":"available"
}
}
]
So just replace the outmost brackets with [] to get an array instead of an object. Here is a demo. See http://www.json.org/ and http://www.json.com/.
You can't. Order is not guaranteed in json and most other key-value data structures. Furthermore you don't have an array, you have an object. Why use name-value pairs at all if you aren't going to use the names to access the values? Therein lies the power of json and other key-value data stores. If you need to access the values by integer indexes, then just use an array to store your data.
Never used JSON, but according to http://labs.adobe.com/technologies/spry/samples/data_region/JSONDataSetSample.html#Example1 , it's possible to create an ordered array. Just remove the key and colon in your key-value pairs. (Someone please tell me whether this works - it may be dependent on values being defined in all objects, or it may allow null columns).