开发者

Loop through JSON data Associatively

开发者 https://www.devze.com 2022-12-25 04:15 出处:网络
How can I loop through this json data without referring to the data items by a number. I would like to use it as an associative array. I have this so far:

How can I loop through this json data without referring to the data items by a number. I would like to use it as an associative array. I have this so far:

$.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');

Example Json Code:

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

Thanks all for any help


Since your element is in the first level, id is available there via this (the current element), like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号