import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class JsonUtil {
//将对象转成JSon格式
public static void writeJson(HttpServletResponse response, Object object){
response.setContentType("application/json; charset=utf-8");
ObjectMapper mapper=new ObjectMapper();
try {
String json = mapper.writeValueAsString(object);
response.getWriter().print(json);
} catch (JsonProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
将对象转成json格式工具类
最新推荐文章于 2024-08-26 03:26:09 发布
关键词由CSDN通过智能技术生成