Tag Archives: Retrofit

Gson Parsing exceptions: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $

First, check whether your retrofit configuration is correct and resolve the exception

.addconverterfactory (gsonconverterfactory. Create()) is modified here to the gson’s

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(HTTP_URL)
        .client(getOkHttpClient())
        .addConverterFactory(GsonConverterFactory.create())
        //Replace the converter, the return value is directly String, easy to parse the same field of different types of json data yourself
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .build();

If this position is like this, report an error

Check whether your API path is correct, and see if there is a missing ‘/’ or something

Retrofit displays the downloaded content

        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(interceptor)
                .retryOnConnectionFailure(true)
                .connectTimeout(15, TimeUnit.SECONDS)
                .build();


        Retrofit retrofit = new Retrofit.Builder().baseUrl(api_url).client(client).addConverterFactory(GsonConverterFactory.create()).build();
                RetrofitService service = retrofit.create(RetrofitService.class);

        Call<ApiGetMapFarms> getMapFarms = service.getMapFarms(api_token, farm_group_id);
        getMapFarms.enqueue(new Callback<ApiGetMapFarms>() {

Note: if the parse line to the parse line, if the copy of the parse will not resolve because of the whitespace problem