关于JSON循环的问题

小弟做了个struts2.1.6和JSON插件结合的例子.
后台的Action有一个Map的属性.采用jquery1.2.6中的Ajax Post请求.
结合后台返回了类似以下的JSON格式.

{
    "photoMap":
    {"57":
    {"menuid":null,"pattribute":1,"pbigname":"big1248081757843.JPG","pid":57,"pinfo":"不能复制吗?不能复制吗?不能复制吗?","pname":"不能复制吗?","psmaname":"small1248081757843.JPG","ptrname":"DSCF1038.JPG","puptime":"2009-07-20T17:22:38","purlpath":"\/image_per\/200907\/person"},
    "56":
    {"menuid":null,"pattribute":1,"pbigname":"big1248081680531.JPG","pid":56,"pinfo":"不能复制吗?不能复制吗?","pname":"不能复制吗?","psmaname":"small1248081680531.JPG","ptrname":"DSCF1008.JPG","puptime":"2009-07-20T17:21:21","purlpath":"\/image_per\/200907\/person"},
    "62":
    {"menuid":null,"pattribute":1,"pbigname":"big1248082855218.JPG","pid":62,"pinfo":"pattributepattribute","pname":"sfsadf","psmaname":"small1248082855218.JPG","ptrname":"DSCF1011.JPG","puptime":"2009-07-20T17:40:55","purlpath":"\/image_per\/200907\/person"}
    }
}

 

类似Map的一个JOSN格式
请高手帮我循环一下,拿到里面的"Key"和"Value".

 

1个回答

var map = {
"photoMap":
{"57":
{"menuid":null,"pattribute":1,"pbigname":"big1248081757843.JPG","pid":57,"pinfo":"不能复制吗?不能复制吗?不能复制吗?","pname":"不能复制吗?","psmaname":"small1248081757843.JPG","ptrname":"DSCF1038.JPG","puptime":"2009-07-20T17:22:38","purlpath":"\/image_per\/200907\/person"},
"56":
{"menuid":null,"pattribute":1,"pbigname":"big1248081680531.JPG","pid":56,"pinfo":"不能复制吗?不能复制吗?","pname":"不能复制吗?","psmaname":"small1248081680531.JPG","ptrname":"DSCF1008.JPG","puptime":"2009-07-20T17:21:21","purlpath":"\/image_per\/200907\/person"},
"62":
{"menuid":null,"pattribute":1,"pbigname":"big1248082855218.JPG","pid":62,"pinfo":"pattributepattribute","pname":"sfsadf","psmaname":"small1248082855218.JPG","ptrname":"DSCF1011.JPG","puptime":"2009-07-20T17:40:55","purlpath":"\/image_per\/200907\/person"}
}
};

var mapData = map["photoMap"];
for(var i in mapData)
{
alert(i);
var obj = mapData[i];

for(var attr in obj )
{
alert("key:" + attr );
alert("value:" + obj[attr] );

}

}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问