Java JsonHttpRH:onSuccess(int,Header[],JSONArray)未被重写,但收到了回调?

Java JsonHttpRH:onSuccess(int,Header[],JSONArray)未被重写,但收到了回调?,java,android,Java,Android,我的应用程序应该显示来自CoingeckoAPI的数据,以下是我尝试过但无法运行的内容 API服务: public class CoinGeckoService { public static final String COINGECKO_GLOBAL_URL = "https://api.coingecko.com/api/v3/global"; private static AsyncHttpClient client = new AsyncHttpClient();

我的应用程序应该显示来自CoingeckoAPI的数据,以下是我尝试过但无法运行的内容

API服务:

public class CoinGeckoService {
    public static final String COINGECKO_GLOBAL_URL = "https://api.coingecko.com/api/v3/global";

    private static AsyncHttpClient client = new AsyncHttpClient();

    public static void getGlobalData(AsyncHttpResponseHandler responseHandler) {
        List<NameValuePair> params = new ArrayList<>();
        try{
            URIBuilder query = new URIBuilder(COINGECKO_GLOBAL_URL);
            query.addParameters(params);
            client.get(query.toString(), responseHandler);
        }
        catch (URISyntaxException e){
            Log.e("URISyntaxException", e.getMessage());
        }
    }

}
但它似乎不起作用,日志显示:JsonHttpRH:onSuccessint,Header[],JSONArray没有被覆盖,但收到了回调


这是来自API的响应数据:

尝试使用改型2。将这些依赖项添加到gradle中。 使用改型是从远程源获取数据的最佳方式

implementation 'com.squareup.retrofit2:retrofit:2.2.0'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
然后创建一个包含基本url的APIURL类

  public class APIUrl {
    public static final String BASE_URL = "https://api.coingecko.com/";
}
然后创建一个包含get参数的APIService类。我的数据应该从此网站生成。

最后,像这样获取数据

 public void getData() {
            Gson gson = new GsonBuilder().setLenient().create();
            Retrofit retrofit = new Retrofit.Builder().baseUrl(APIUrl.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();

            APIService apiService = retrofit.create(APIService.class);
            Call<MyData> call = apiService.getData();
            call.enqueue(new Callback<VeriListem>() {
                @Override
                public void onResponse(Call< MyData > call, Response< MyData > response) {
                   // this gives you all data as MyData type and do your operation here
                }

                @Override
                public void onFailure(Call<MyData> call, Throwable t) {
                    Log.d("error", t.getMessage().toString());
                }
            });
        }

要创建MyData,请粘贴json响应并选择源类型:json,注释样式:GSON。
  public class APIUrl {
    public static final String BASE_URL = "https://api.coingecko.com/";
}
public interface APIService {
    @GET("api/v3/global")
    Call<MyData> getList();
}
 public void getData() {
            Gson gson = new GsonBuilder().setLenient().create();
            Retrofit retrofit = new Retrofit.Builder().baseUrl(APIUrl.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();

            APIService apiService = retrofit.create(APIService.class);
            Call<MyData> call = apiService.getData();
            call.enqueue(new Callback<VeriListem>() {
                @Override
                public void onResponse(Call< MyData > call, Response< MyData > response) {
                   // this gives you all data as MyData type and do your operation here
                }

                @Override
                public void onFailure(Call<MyData> call, Throwable t) {
                    Log.d("error", t.getMessage().toString());
                }
            });
        }