我在用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:
json
public class ApplyInfo {ide
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;
ui
不然 List 對象不能被轉換
spa