Retrofit2.0 gets MalformedJsonException while the json seems correct? Retrofit2.0 gets MalformedJsonException while the json seems correct? json json

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();


I solved the problem

Gson gson = new GsonBuilder().setLenient().create();OkHttpClient client = new OkHttpClient();Retrofit retrofit = new Retrofit.Builder()    .baseUrl("http://kafe.netai.net/")    .client(client)    .addConverterFactory(GsonConverterFactory.create(gson))    .build();compile 'com.squareup.retrofit2:retrofit:2.1.0'compile 'com.squareup.retrofit2:converter-gson:2.1.0'compile 'com.google.code.gson:gson:2.7'


I solved my problem by removing extra HTML text and other white spaces from my JSON file.