一、创建相应实体:

public class ExpressStatusVO {

private String ftime;
private String context;// 信息内容
private String time;

public String getFtime() {
return ftime;
}

public void setFtime(String ftime) {
this.ftime = ftime;
}

public String getContext() {
return context;
}

public void setContext(String context) {
this.context = context;
}

public String getTime() {

return time;
}

public void setTime(String time) {
this.time = time;
}

}

二、获取Gson对象并进行转换:

public Object getExpressDetails( ){

String strByJson = "[{"ftime":"2017-11-15 22:03:32","context":"客户 签收人: 牛春平 已签收  感谢使用圆通速递,期待再次为您服务","time":"2017-11-15 22:03:32"},

{"ftime":"2017-11-15 16:28:38","context":"北京市昌平区北七家公司(点击查询电话)居** 派件中 派件员电话15501296544","time":"2017-11-15 16:28:38"},

{"ftime":"2017-11-15 05:52:22","context":"北京市昌平区北七家公司 已收入","time":"2017-11-15 05:52:22"},

{"ftime":"2017-11-15 01:36:57","context":"北京转运中心 已发出,下一站 北京市昌平区北七家","time":"2017-11-15 01:36:57"}]";

String strByJson = expressStatus.getData();
// Json to list
ExpressStatusVO[] array = new Gson().fromJson(strByJson, ExpressStatusVO[].class);
List<ExpressStatusVO> listVO = Arrays.asList(array);

Map<String, Object> map = new HashMap<String, Object>();

map.put("list", listVO);

return map;

}

返还的对象为:

 "list": [
        {
          "ftime": "2017-11-15 22:03:32",
          "context": "客户 签收人: 牛春平 已签收  感谢使用圆通速递,期待再次为您服务",
          "time": "2017-11-15 22:03:32"
        },
        {
          "ftime": "2017-11-15 16:28:38",
          "context": "北京市昌平区北七家公司(点击查询电话)居** 派件中 派件员电话15501296544",
          "time": "2017-11-15 16:28:38"
        },
        {
          "ftime": "2017-11-15 05:52:22",
          "context": "北京市昌平区北七家公司 已收入",
          "time": "2017-11-15 05:52:22"
        },
        {
          "ftime": "2017-11-15 01:36:57",
          "context": "北京转运中心 已发出,下一站 北京市昌平区北七家",
          "time": "2017-11-15 01:36:57"
        }]
注意:前台需要的是list集合时,需将其转为Map对象进行返回。

 

posted on 2019-01-28 23:31  qqzhulu  阅读(728)  评论(0编辑  收藏  举报