數組中的第一個元素不是一個對象,它是一個字符串。這就是爲什麼當你說grab.AgentFullName
時,第一個元素沒有定義 - 字符串「results」沒有這樣的屬性。
你可以改變
[
"results",
{
"InteractionID":"1",
"AgentFullName":"Peter Germein",
"InteractTopics":"Behaviour, Attendance, Attitude, Performance, Closing",
"InteractDiscussion":"Cras at nisl lorem, a lacin...",
"InteractAction":"Morbi quis nunc in odio eg...",
"InteractNotes":"Quisque et ante ut nis..."
},
到
[
{
"InteractionID":"1",
"AgentFullName":"Peter Germein",
"InteractTopics":"Behaviour, Attendance, Attitude, Performance, Closing",
"InteractDiscussion":"Cras at nisl lorem, a lacin...",
"InteractAction":"Morbi quis nunc in odio eg...",
"InteractNotes":"Quisque et ante ut nis..."
},
或者是你想這樣做:
{
"results": [
{
"InteractionID":"1",
"AgentFullName":"Peter Germein",
"InteractTopics":"Behaviour, Attendance, Attitude, Performance, Closing",
"InteractDiscussion":"Cras at nisl lorem, a lacin...",
"InteractAction":"Morbi quis nunc in odio eg...",
"InteractNotes":"Quisque et ante ut nis..."
},
{
"InteractionID":"2",
"AgentFullName":"Peter Germein",
"InteractTopics":"Behaviour, Attendance, Attitude, Performance, Closing",
"InteractDiscussion":"....",
"InteractAction":"Morbi quis nunc in ...",
"InteractNotes":"Quisque et ante ut nisi ..."
},
這將是解析如下:
$.each(data.results, function(i, grab){
alert(grab.AgentFullName);
})
謝謝,這就是我要去的地方。但是,我將如何糾正這在我的PHP文件。它使用json_ncode。這可能是沒有足夠的信息,所以你可以在這裏找到Interactions.php的內容: [link] http://pastebin.com/3KjDG0sF – Poika 2012-01-04 04:32:12
試試這個,在第12行** $ return_arr = array(「results」); **,將數組(「結果」)更改爲array()。然後在第33行和第37行之間的任何一行中,放入** $ temp_arr = array(); $ temp_arr [「results」] = $ return_arr; $ return_arr = $ temp_arr; **(該點是將json數組設置爲數組索引或列稱爲結果) – vicker313 2012-01-04 04:52:39
先生,你是一個完整的傳奇!感謝您的時間! – Poika 2012-01-04 04:55:27