zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

JSList对象JSONJSON 解析 示例 读取
2023-06-13 09:15:19 时间

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

复制代码代码如下:

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

List中存放多个student对象

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

varobj=eval("("+data+")");

3、遍历取list中的对象
复制代码代码如下:
for(varkeyinobj){//第一层循环取到各个list
varList=obj[key];
for(varstudentinList){//第二层循环取list中的对象
alert(List[student].id);
alert(List[student].name);
}
}

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

在线json压缩/转义工具: