2010-04-01 4 views
0

Comment faire une boucle sur ces données json sans faire référence aux données par un nombre. Je voudrais l'utiliser comme un tableau associatif. J'ai ce jusqu'à présent:Boucle dans les données JSON Associativement

$.post('/controlpanel/search', { type: type, string: string }, function(data){ 

     $.each(data, function() { 

      $.each(this, function(index, itemData) { 

         //alert(data.id) something like this 
         //currently returns undefined 

      }); 

     }); 

    }, 'json'); 

Exemple Json code:

[{"id":"1","title":"","link":"http:\/\/www.msn.com","date_added":"0000-00-00 00:00:00", 
"privacy_type":"0","user_id":"8","field2":"","field3":"","bookmark_id":"70","tag":"clean"}] 

Merci à tous pour toute aide

Répondre

3

Étant donné que votre élément est dans le premier niveau, id y est disponible via this (le élément actuel), comme ceci:

$.post('/controlpanel/search', { type: type, string: string }, function(data){ 
    $.each(data, function() { 
    alert(this.id); 
    }); 
}, 'json'); 
+0

God Damn! Merci ça a marché. :) – Abs

+0

@Abs - Bienvenue :) –