Retrofit2.0 gets MalformedJsonException while the json seems correct?

前端 未结 3 1139
北海茫月
北海茫月 2020-11-29 08:12

I am using retrofit:2.0.0-beta4 for my android app.

I tried to add a user with Retrofit, the user is correctly created in Database, however I got the following error

3条回答
  •  渐次进展
    2020-11-29 08:34

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

提交回复
热议问题