2012-01-29 60 views
0

如何檢索使用jquery從php數組數組轉換而來的json數據?我有這個PHP numical陣列....如何檢索來自php數組數組的json數據?

     while(tests < totalResults) 
         { 
          $testResults[$columnIndex] = '<p>' . $log_info . '</p>'; 
         } 
         $jsonData = json_encode($testResults); 
         echo $jsonData; 

這是我使用jQuery如何獲取上述PHP代碼,但不郊遊什麼...

    $.getJSON("test.php",function(data) 
       { 
         $.each(data, function(key, value) 
         { 
         $("#test li:eq(0)").appendTo(value[key]); 
         }); 
       });    

回答

0

value參數不是數組,這是來自該數組的項目的值。

$("#test li:eq(0)").appendTo(value); 

請注意,您是從數組中的字符串創建元素,向他們添加一個子元素並將其扔掉。也許你想使用append方法。

0

value[key]更改爲value,因爲循環回調中的第二個參數指向數組的當前值。試試這個

$.getJSON("test.php",function(data) 
       { 
         $.each($(data), function(key, value) 
         { 
         $("#test li:eq(0)").appendTo(value); 
         }); 
       });