java对象转JSON JS取JSON数据

来源:互联网 发布:感恩 知乎 编辑:程序博客网 时间:2024/05/16 18:37
JsonConfig config = new JsonConfig();
config.setJsonPropertyFilter(new PropertyFilter() {
@Override

public boolean apply(Object arg0, String arg1, Object arg2) {


// 过滤掉对象里的包含自己的属性(自己关联自己)

if (arg1.equals("wareTypes") || arg1.equals("skillS")) {
return true;
} else {
return false;
}
}
});


// 转化为JSON

JSONArray json = JSONArray.fromObject(userList, config);


JSP页面取数据

var obj = eval( "(" + data + ")" );//转换后的JSON对象
alert(obj[0].username);

0 0
原创粉丝点击