M
M
mr_serg772017-10-19 17:59:29
Android
mr_serg77, 2017-10-19 17:59:29

How to get json from .gz file using Okhttp + Retrofit?

There is a data.json.gz file on the server
Inside a regular Json array with objects

[
{
"name": "name"
},
...
]

request interface:
@Headers({
            "Content-Type: application/json;charset=utf-8",
            "Accept: application/json"
    })
    @GET("/data.json.gz")
    Call<List<Data>> loader();

request initialization:
Retrofit retrofit;
        iRequest iRequest;
        Call<List<Data>> call;
        Gson gson;
        gson = new GsonBuilder()
                .setLenient()
                .create();
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(new OkHttpClient())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
        iRequest = retrofit.create(iRequest.class);
        call = iRequest.loader();

mistake:
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $

Please tell me what is missing? It seems that I need to dig in the direction of Okhttp, but I don’t realize something.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2017-10-19
@mr_serg77

Obviously, there is no required header. Googled for you: https://stackoverflow.com/a/37370050

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question