Hi,
first i would rather suggest to not use numbers as array name... in your
example you will have problem while debuggin code and i'm not sure that it
will work correctly.
so i would suggest instead of using 9 to use something else but with
characters.

you can do something like that (where myarray is corresponding to your 9:

for (i in myarray)
{
   var _title = myarray[i].title;
   var _style = myarray[i].style;
   ...
}

HTH,

Alain


On Sat, Feb 21, 2009 at 12:51 PM, newkid85 <newki...@googlemail.com> wrote:

>
> If I have JSON data like this:
>
> { "9": { "title": "Event 1", "style": "rock" }, "11": { "title":
> "Event 2", "style": "pop" }, "15": { "title": "Event 3", "style":
> "house" }, "16": { "title": "Event 4", "style": "metal"} }
>
> How can I loop through each item grabbing each key/value pair for
> outputting? Is this possible with $.each?
> I tried the following:
>
> var event = '';
> $.each(results, function(title, style) {
>               event += '<div>' + title + ' ' + style +  '<\/div>';
> });
> $('#events').html(event);
>
> But it returned
>
> 9 [object Object]
> 11 [object Object]
> 15 [object Object]
> 16 [object Object]
>
> I'm guessing my syntax is wrong or I am misusing the function. Any
> help appreciated.




-- 
Alain
-----------------------------------------------------------
Windows XP x64 SP2 / Fedora 10 KDE 4.2
PostgreSQL 8.3.5 / MS SQL server 2005
Apache 2.2.10
PHP 5.2.6
C# 2005-2008

Reply via email to