浅谈Java后台对JSON格式的处理操作
1.将对象转换为JSON字符串,返回值为一个JSON字符串
publicstaticStringtoJson(Objectvalue){
try{
returnmapper.writeValueAsString(value);
}catch(Exceptione){
e.printStackTrace();
}
returnnull;
}
2. 将JSON字符串转换为实体对象,返回值为实体对象
publicstatic<T>TtoObject(Stringjson,Class<T>valueType){
Assert.hasText(json);
Assert.notNull(valueType);
try{
SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");
mapper.setDateFormat(dateFormat);
returnmapper.readValue(json,valueType);
}catch(Exceptione){
e.printStackTrace();
}
returnnull;
以上这篇浅谈Java后台对JSON格式的处理操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。