......ui
// 經過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();
}orm
--------解析完畢,下面是自定的4個實體類,和接口返回數據對應--------接口
public class TotalResponse {get
private TradeRateResponse traderates_get_response;class
getter、setter以及toString略
}List
public class TradeRateResponse {request
private Integer total_results;
private String request_id;
private TradeRatess trade_rates;數據
getter、setter以及toString略
}時間
public class TradeRatess {co
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"}}