GsonUtil

2017-01-20  本文已影响0人  暮色雨林

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\"}]}");

注意这里的大括号

上一篇下一篇

猜你喜欢

热点阅读