如何在Retrofit 2.0中无需转换即可获取JSON对象?

use*_*670 5 rest android json

我需要从REST服务器下载json对象而不用GSON转换.但不明白如何制作Retrofit 2.0 bata 1

hac*_*tsu 7

简单地JsonElement用作你的pojo.例如

在你的FlowerApi interfce中:

    @GET("/flower")
    Call<JsonElement> getFlowers();
Run Code Online (Sandbox Code Playgroud)

在你的主要课程中:

    Call<JsonElement> getFlowersCall = httpApiClass.getFlowers();

    getFlowersCall.enqueue(new Callback<JsonElement>() {
        @Override
        public void onResponse(Response<JsonElement> response, Retrofit retrofit) {
            JsonElement jsonElement = response.body();
            Log.d(TAG, jsonElement.toString());
        }

        @Override
        public void onFailure(Throwable t) {
            Log.d(TAG, "Failed: " + t.getMessage());
        }
    });
Run Code Online (Sandbox Code Playgroud)

实际上,响应仍然JsonElement由Gson转换器转换,但是你可以获得接近原始响应的东西.