相关疑难解决方法(0)

如何从函数onResponse of Retrofit返回值?

我试图返回一个从调用请求中的onResponse方法获得的值,retrofit有没有办法可以从覆盖的方法中获取该值?这是我的代码:

public JSONArray RequestGR(LatLng start, LatLng end)
    {
       final JSONArray jsonArray_GR;

        EndpointInterface loginService = ServiceAuthGenerator.createService(EndpointInterface.class);    
        Call<GR> call = loginService.getroutedriver();
        call.enqueue(new Callback<GR>() {
            @Override
            public void onResponse(Response<GR> response , Retrofit retrofit)
            {

                 jsonArray_GR = response.body().getRoutes();
//i need to return this jsonArray_GR in my RequestGR method
            }
            @Override
            public void onFailure(Throwable t) {
            }
        });
        return jsonArray_GR;
    }
Run Code Online (Sandbox Code Playgroud)

我无法得到价值,jsonArray_GR因为能够在onResponse方法中使用它我需要声明它最终,我不能给它一个值.

java methods json retrofit

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

json ×1

methods ×1

retrofit ×1