【发布时间】:2019-01-02 20:21:59
【问题描述】:
我想从我的函数中返回一个字符串值。但不知如何处理?我尝试了最终的单数组解决方案,但没有成功。
这是我的代码:
public String revealCourtPlace(String courtID)
{
BaseService.getInstance().getUniqueCourt(Session.getToken(),courtID).enqueue(new Callback<JsonObject>()
{
@Override
public void onResponse(Call<JsonObject> call, Response<JsonObject> response)
{
JsonObject object = response.body();
boolean success = object.get("success").getAsBoolean(); //json objesinde dönen success alanı true ise
if (success)
{
JsonArray resultArray = object.get("data").getAsJsonObject().get("result").getAsJsonArray();
for (int i = 0; i < resultArray.size(); i++)
{
JsonObject jsonInfoResult = resultArray.get(i).getAsJsonObject();
String courtName=jsonInfoResult.get("name").getAsString();
}
}
}
@Override
public void onFailure(Call<JsonObject> call, Throwable t)
{
}
});
//return ?
}
【问题讨论】:
-
onResponse被异步调用,即很有可能在您从revealCourtPlace返回之后。 -
你说,有没有办法获取字符串值?
-
你需要构建你的逻辑以使其更具反应性,例如响应异步事件/更新。以
RxJava为例(retrofit也支持RxJava) -
你使用什么包包含
JsonObject?为什么不org.json?
标签: android retrofit retrofit2