Error: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path

First Check your server response is valid JSON or Not if not make it proper

To check the resposne you can add loggingInterceptor for OkHttpClient  

OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(new LoggingInterceptor()).build();
                
                static class LoggingInterceptor implements Interceptor {
        @Override
        public Response intercept(Interceptor.Chain chain) throws IOException {
            Request request = chain.request();

            long t1 = System.nanoTime();
            Log.v("Request ",String.format("Sending request %s on %s%n%s",
                    request.url(), chain.connection(), request.headers()));

            Response response = chain.proceed(request);

            long t2 = System.nanoTime();
            Log.v("Request ",String.format("Received response for %s in %.1fms%n%s",
                    response.request().url(), (t2 - t1) / 1e6d, response.headers()));


            final String responseString = new String(response.body().bytes());

            Log.v("Request ","Response: " + responseString);

            return  response.newBuilder()
                    .body(ResponseBody.create(response.body().contentType(), responseString))
                    .build();
        }}

 

If every thing fine add GsonConverter with below code

 GsonBuilder gsonBuilder=new GsonBuilder();
        gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
        gsonBuilder.setLenient();
        

 

Finally Retrofit object creation should be like below

Retrofit.Builder()
        .addConverterFactory(GsonConverterFactory.create(gsonBuilder.create()))
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
        .baseUrl(ApiCall.BASE_IRL)
        .client(client)
        .build();

 


Flutter Questions

Android Questions

Python Questions

Java Questions