json工具类------将指定Java对象转为json

public void java2Json(Object o ,String[] exclueds){

JsonConfig jsonConfig = new JsonConfig();

//指定哪些属性不需要转json

jsonConfig.setExcludes(exclueds);

String json = JSONObject.fromObject(o,jsonConfig).toString();

ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");

try {

ServletActionContext.getResponse().getWriter().print(json);

} catch (IOException e) {

e.printStackTrace();

}

}

猜你喜欢

转载自blog.csdn.net/itcats_cn/article/details/80200727