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;热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短