标签:long getter amp 设置 builder 解决 orm 实例 ons
......
// 通过GSON解析,使用4个实体类来接受(TotalResponse、TradeRateResponse、TradeRatess、TbTradeRates)
GsonBuilder gsonBuidler = new GsonBuilder();//使用GsonBuilder来创建Gson,可以设置时间转换格式。
gsonBuidler.setDateFormat("yyyy-MM-dd HH:mm:ss");
Gson gson = gsonBuidler.create();
TotalResponse getResponse = gson.fromJson(rsp.getBody(),
TotalResponse.class);
List<TbTradeRates> tbTradeRatesList = new ArrayList<TbTradeRates>();
if (getResponse != null && getResponse.getTraderates_get_response() != null && getResponse.getTraderates_get_response().getTrade_rates() != null) {
tbTradeRatesList = getResponse.getTraderates_get_response().getTrade_rates().getTrade_rate();
}
--------解析完毕,下面是自定的4个实体类,和接口返回数据对应--------
public class TotalResponse {
private TradeRateResponse traderates_get_response;
getter、setter以及toString略
}
public class TradeRateResponse {
private Integer total_results;
private String request_id;
private TradeRatess trade_rates;
getter、setter以及toString略
}
public class TradeRatess {
private List<TbTradeRates> trade_rate;
getter、setter以及toString略
}
public class TbTradeRates {
private Long id;
private String oid;
private String tid;
...
getter、setter以及toString略
}
接口返回JSON:
{"traderates_get_response":
{"total_results":2,
"trade_rates":
{"trade_rate":
[{
"content":"好评!",
"nick":"小黑",
"num_iid":72896,
"oid":993,
"tid":39993},
{"content":"好评!",
"nick":"小黑",
"num_iid":5443,
"oid":13743,
"tid":413493,
}]},
"request_id":"cx"}}
标签:long getter amp 设置 builder 解决 orm 实例 ons
原文地址:http://www.cnblogs.com/ztk1994/p/6526966.html