Try something like this (if you can't re-structure the JSON Object):

$.each(myJSONObject.formValues, function(i,item) {
    var itemtxt = 'Object details for formValues['+i+']:\n\n';
    for (prop in item) {
        itemtxt += prop + ': ' + item[prop] + '\n';
    } 
    alert(itemtxt);
});

For the type of data you are using in your example, the previous reply gives
a better way of doing it.


bob-301 wrote:
> 
> 
> How do I dynamically access json values?
> 
> var myJSONObject = {"formValues": [
>         {'name': 'Frank'},
>         {'city': 'London'},
>               {'age': 25}
>               ]
> };
> 
> The following gives me undefined.
> 
> 
> $.each(myJSONObject.formVals, function(i,item){
> 
>       alert('i = ' + i + '   item0 = ' + item[0] + '   item1 = ' + item
> [1]);
> });
> 
> 

-- 
View this message in context: 
http://www.nabble.com/iterate-over-json-tp21304386s27240p21308189.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to