我有一个由 PHP 发送到 Javascript 的动态生成的数组。它基本上是一组未读消息。它包含发件人的姓名和他们发送的消息。
鉴于我不知道名字,我如何检索他们的名字和他们的消息?
{"Emma Giles":
[{"message":"Hi Phil","date":"Tue 10 May 2:55 PM 2011"}],
"Johnathan Macmanners":
[{"message":"Hi Emma","date":"Sun 26 June 10:03 PM 2011"}],
"Ellen Murley":
[{"message":"Hello","date":"Fri 04 May 4:05 PM 2012"},
{"message":"How are you?","date":"Fri 04 May 2:52 PM 2012"}],
"Amanda Patterson":
[{"message":"test","date":"Fri 27 April 10:07 AM 2012"}],
"ALEX Pell":
[{"message":"Hi Alvon","date":"Mon 05 March 10:07 AM 2012"}]}
我已经尝试过了,但由于某种原因它只打印出数字,我用 val 替换了 key ,它一个一个地打印出数组中的每个字符。:
$.each(data, function(key, val)
{
console.log(key);
});