我在用gson做stringJSON 转换bean的时候,因为该bean内部嵌套对象,找了半天才找到他的用法,所有拿出共享一下
GsonBuilder builder = new GsonBuilder();
//builder.excludeFieldsWithoutExposeAnnotation();
Gson gson = builder.create();
//嵌套bean 对象用法
ApplyInfo user2 = gson.fromJson(json, new TypeToken<ApplyInfo>(){}.getType());
return user2;
其中ApplyInfo:
public class ApplyInfo {
private String cnName;
private String compCode;
private String enName;
private String costCenter;
private String travelType;
private String reason;
private String budget;
private List<TravelInfo> travelInfo;
private List<CarInfo> carInfo;
private List<HotelInfo> hotelInfo;
否则 List 对象不能被转换