groupList1(@QueryMa-6ren">
gpt4 book ai didi

android - 使用 QueryMap 改造

转载 作者:太空狗 更新时间:2023-10-29 13:58:29 25 4
gpt4 key购买 nike

我有一些请求具有相同的端点,但参数和返回类型不同。

我用了@QueryMap作为参数,但我不知道如何写返回类型:

我必须写:

@GET("xxx")
Call<List<A1>> groupList1(@QueryMap Map<String, String> options);
@GET("xxx")
Call<List<A2>> groupList2(@QueryMap Map<String, String> options);
@GET("xxx")
Call<List<A3>> groupList3(@QueryMap Map<String, String> options);
....

或者有更短的解决方案?

最佳答案

你可以使用JsonElement响应类型

 @GET("xxx")
Call<JsonElement> groupList(@QueryMap Map<String, String> options);

每次调用您都会收到 JsonElement,您可以将其转换为 JsonObjectJsonArray 甚至 String。您可以根据您的内容解析/取消实现它

public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {
JsonElement jsonElement = response.body();
//JsonArray array = jsonElement.getAsJsonArray();
//JsonObject Obj = jsonElement .getAsJsonObject();
}

关于android - 使用 QueryMap 改造,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37766953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com