js解析json读取List中的实体对象示例

 更新时间:2014年03月11日 16:04:45   投稿:whsnow  
这篇文章主要介绍了js解析json读取List中的实体对象的具体实现,需要的朋友可以参考下

1、由后台action 传给前台是需要将map 转成json格式

复制代码 代码如下:

Map<String, List> resultMap;
JSONObject json = JSONObject.fromObject(resultMap);
message = json.toString();

List中存放多个student对象

2、前台js 中先将结果json串转成对象
复制代码 代码如下:

var obj = eval("("+data+")");

3、遍历取list 中的对象
复制代码 代码如下:

for(var key in obj){ //第一层循环取到各个list
var List = obj[key];
for(var student in List){ //第二层循环取list中的对象
alert(List[student ].id);
alert(List[student ].name);
}
}

PS:关于json操作,这里再为大家推荐几款比较实用的json在线工具供大家参考使用:

在线JSON代码检验、检验、美化、格式化工具:
http://tools.jb51.net/code/json

JSON在线格式化工具:
http://tools.jb51.net/code/jsonformat

在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson

json代码在线格式化/美化/压缩/编辑/转换工具:
http://tools.jb51.net/code/jsoncodeformat

在线json压缩/转义工具:

http://tools.jb51.net/code/json_yasuo_trans

C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json

相关文章

最新评论