簡體   English   中英

關聯循環遍歷JSON數據

[英]Loop through JSON data Associatively

如何在不通過數字引用數據項的情況下遍歷此json數據。 我想將其用作關聯數組。 到目前為止,我有:

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

示例Json代碼:

[{"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"}]

謝謝大家的幫助

由於您的元素位於第一級,因此可以通過this (當前元素)在其中使用id ,如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM