![java对象转JSON JS取JSON数据 java对象转JSON JS取JSON数据](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
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);