You know, I didn't even realise it, having just been working on a lot
of PHP with  "${variables} inside strings". Yeah, that is unwieldy.

On Tue, Jan 6, 2009 at 12:33 AM, Michael Geary <m...@mg.to> wrote:
>
> That's an unusual JSON object. Does it really have to be structured that
> way, or do you have some choice about it? It's going to be pretty awkward to
> work with as it is. You can do it, but it involves a lot of code that
> wouldn't be necessary if the JSON object were structured in a more
> conventional way.
>
> Given the kind of data you have in the object, I'd want to work with
> something like this instead:
>
>    var myJSONObject = {
>        "formValues": {
>            "name": "Frank",
>            "city": "London",
>            "age": 25
>        }
>    };
>
> Then it becomes trivial:
>
>  myJSONObject.formValues.name  // "Frank"
>  myJSONObject.formValues.city  // "London"
>  myJSONObject.formValues.age  // 25
>
> If you can't change the data format, give a shout back and we can talk about
> how to work with it.
>
> -Mike
>
>> -----Original Message-----
>> From: jquery-en@googlegroups.com
>> [mailto:jquery...@googlegroups.com] On Behalf Of bob
>> Sent: Monday, January 05, 2009 8:05 PM
>> To: jQuery (English)
>> Subject: [jQuery] iterate over json
>>
>>
>> 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]);
>> });
>>
>
>

Reply via email to