GsonUtil

public classGsonUtil implements ParameterizedType {

publicTdeal(String response) {

try{

Type gsonType =this;

BaseStringResponse baseStringResponse =newGson().fromJson(response,gsonType);

returnbaseStringResponse.getData();

}catch(Exception e) {

e.printStackTrace();

}

return null;

}

@Override

publicType[]getActualTypeArguments() {

Class clz =this.getClass();

Type superclass = clz.getGenericSuperclass();

if(superclassinstanceofClass) {

throw newRuntimeException("Missing type parameter.");

}

ParameterizedType parameterized = (ParameterizedType) superclass;

returnparameterized.getActualTypeArguments();

}

@Override

publicTypegetOwnerType() {

return null;

}

@Override

publicTypegetRawType() {

returnBaseStringResponse.class;

}

}

调用 :List resultList =newGsonResponsePasare>() {

}.deal("{\"status\":-4,\"data\":[{\"name\":\"xiaoxuan948\"},{\"name\":\"coca\"}]}");

注意这里的大括号

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,810评论 19 139
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 32,322评论 18 399
  • 一. Java基础部分.................................................
    wy_sure阅读 9,281评论 0 11
  • 感恩今天阴天还灰蒙蒙的,让我们更加珍惜阳光明媚的日子。 感恩昨天晚上发烧,今天一早又正常起床做饭,没有找借口,早饭...
    俩宝的妈咪阅读 1,180评论 0 0
  • 简洁的含义~ 观点清晰 信息突出 噪音减少
    xzja阅读 1,792评论 0 0

友情链接更多精彩内容