调接口返回String类型转列表
Posted 十壹、
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了调接口返回String类型转列表相关的知识,希望对你有一定的参考价值。
调接口返回String类型转列表
Gson gson = new Gson();
List persons = gson.fromJson(str, new TypeToken<List>().getType());
public String getBeforeCreateGroupType(String type, String userIds)
String baseUrl = ApiGatewayUtils.getApiGatewayUrl();
Retrofit retrofit = HttpClient.getInstance().createRetroft(baseUrl);
RequestServes service = retrofit.create(RequestServes.class);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("action", "teamaddgettypes");
BeforeCreateGroupTypeBody beforeCreateGroupTypeBody =new BeforeCreateGroupTypeBody();
beforeCreateGroupTypeBody.setTeamType(type);
beforeCreateGroupTypeBody.setUserIds(userIds);
Gson gson =new Gson();
String data = gson.toJson(beforeCreateGroupTypeBody);
jsonObject.addProperty("body", data);
RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), jsonObject.toString());
try
BaseResponse<String> baseResponse = service.getBeforeCreateGroupType(body).execute().body();
if (baseResponse != null && baseResponse.getResult() != null)
beforeCreateGroupResults = baseResponse.getResult();
Gson gsonN = new Gson();
beforeCreateGroupTypes = gsonN.fromJson(beforeCreateGroupResults, new TypeToken<List<BeforeCreateGroupType>>().getType());
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
return beforeCreateGroupResults;
beforeCreateGroupTypes 是一个List列表
public class BeforeCreateGroupType implements Serializable
private String name;
private String fkDomain;
private int teamType;
public String getName()
return name;
public void setName(String name)
this.name = name;
public String getFkDomain()
return fkDomain;
public void setFkDomain(String fkDomain)
this.fkDomain = fkDomain;
public int getTeamType()
return teamType;
public void setTeamType(int teamType)
this.teamType = teamType;
以上是关于调接口返回String类型转列表的主要内容,如果未能解决你的问题,请参考以下文章