调接口返回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类型转列表的主要内容,如果未能解决你的问题,请参考以下文章

调接口返回String类型转列表

feign接口调用时问题整理

Spring Cloud Zuul 实现路由,获取参数

GRPC的HTTP返回值int64被转为string类型

java 怎么把数组转为list

和app提供接口调接口那些事