Retrofit2.0 gets MalformedJsonException while the json seems correct?

Finally I solved my problem which is not related to the json lenient mode, something wrong with my POST response (there some other non json output before the json data).

Here is the response from JakeWharton regarding how to set Gson lenient mode:

make sure that you haveļ¼šcompile 'com.google.code.gson:gson:2.6.1'

Gson gson = new GsonBuilder()
        .setLenient()
        .create();

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(client)
        .addConverterFactory(GsonConverterFactory.create(gson))
        .build();

Leave a Comment