LoginSignup
5

More than 5 years have passed since last update.

【Android】RetrofitでUse JsonReader.setLenient(true) to accept malformed JSONのエラーが出たときの対処法

Posted at

結論

setLenient()を有効にしたGsonオブジェクトをGsonConverterFactory.create()に渡す。

環境

retrofit version: 2.3.0

エラー内容

com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 2 column 5 path $

サンプルコード

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

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

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5