2011-05-01 41 views
0

當我使用Ajax JSON一個json_encoded陣列,我是輸出像通常的陣列的Ajax jquery的JSON陣列輸出問題

元件[0]

$.ajax({          
    url: 'url.php',     
    data: "",          
    dataType: 'json',      
    success: function(element)   
    { 
    $('#content').html(element[0]); 
    } 
}); 

我從編碼得到infro元素json thtat在url中,但它只輸出[object Object]

+0

'像通常的陣列'是使這不起作用的部分。嘗試在這裏轉儲jSon對象;) – 2011-05-01 08:23:59

回答

2

也許這個元素有一些屬性。例如,如果返回的JSON是這樣的:

[ { "someProperty": "value 1" }, { "someProperty": "value 2" } ] 

你可以:

$('#content').html(element[0].someProperty); 
+0

完美:) Thnx – weardstuff 2011-05-01 08:28:46

0

這是因爲對象的toString()返回[object Object]。您需要決定如何輸出Object。檢查它的屬性,然後選擇你需要的屬性,例如element.something