Wednesday, January 13, 2010

JSON Associative Arrays

Given a JSON associative array of the following format:
var myList = {'123' : 'big', '456':'small'}

I wanted to be able to parse through this array whilst examining both the value of the key and..ummm...the value of the value. After a bit of searching, I came up with the solution:


for (var item in myList)
{
alert(item); // will display '123' and then '456'
alert(myList[item]); // will display 'big' and then 'small'
}

No comments:

Post a Comment