当前位置: 移动技术网 > IT编程>开发语言>Java > Java后台处理Json格式数据的方法

Java后台处理Json格式数据的方法

2019年07月22日  | 移动技术网IT编程  | 我要评论

 1.将对象转换为json字符串,返回值为一个json字符串

public static string tojson(object value) {
try {
return mapper.writevalueasstring(value);
} catch (exception e) {
e.printstacktrace();
}
return null;
}

2. 将json字符串转换为实体对象,返回值为实体对象

public static <t> t toobject(string json, class<t> valuetype) {
assert.hastext(json);
assert.notnull(valuetype);
try {
simpledateformat dateformat = new simpledateformat("yyyy-mm-dd hh:mm:ss");
mapper.setdateformat(dateformat);
return mapper.readvalue(json, valuetype);
} catch (exception e) {
e.printstacktrace();
}
return null;

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网