fastJson将json对象转为java对象,属性名不同的映射(@JSONField)

JSONObject.toJavaObject(JSON json,Class<T> clazz);  

功能:1.将json转为java对象

   2.json中下划线格式自动映射到java属性中驼峰格式‘

   3.如果json中的字段和要映射的java属性名不同,可以在java类要映射的属性的set方法上添加@JSONField注解’,如下可以把json中“peer_count”字段值映射到java中“count”属性上。

@JSONField(name = "peer_count")
public void setCount(String count) {
this.count = count;
}

猜你喜欢

转载自www.cnblogs.com/fangyan1994/p/12419254.html