引用:
compile "com.google.code.gson:gson:$gsonVersion"
dependencies { implementation 'com.google.code.gson:gson:2.8.4' }
高版本 AS,都是使用implementation
序列化:
public class AdvertiseListRequestBean extends CommonRequestBean { public String user; public AdvertiseListRequestBean(){ super(); sn=getSn(); cmd=Web.WEB_CMD_AD_GETLIST; } }
AdvertiseListRequestBean mAdvertiseListRequestBean = new AdvertiseListRequestBean(); mAdvertiseListRequestBean.user=lastUserName; String json = mGson.toJson(mAdvertiseListRequestBean);
反序列化 public class AdvertiseListResponseBean extends CommonResponseBean { public BodyClass body=new BodyClass(); public class BodyClass { public int errorcode; public List<AdvertiseBean> list = new ArrayList<AdvertiseBean>(); } }
AdvertiseListResponseBean mAdvertiseListResponseBean = mGson.fromJson(json, AdvertiseListResponseBean.class);