使用JsonReader.setLenient(true)在改版android中接受格式错误的JSON

时间:2019-10-28 08:31:11

标签: android json android-studio gson retrofit2

我正在使用翻新并出现此错误,为什么我得到此错误?是响应还是请求的问题? 我得到的响应是简单的json {“错误”:“已在请求中”}

public static Retrofit getRetrofitInstance2(final String token){
    if (retrofit == null) {
        Gson gson = new GsonBuilder()
                .setLenient()
                .create();
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Chain chain) throws IOException {
                        Request newRequest  = chain.request().newBuilder()
                                .addHeader("Authorization", "Bearer " + token)
                                .header("Content-Type","application/json")
                                .build();
                        return chain.proceed(newRequest);
                    }
                })
                .build();
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
    }
    return retrofit;
}



@SerializedName("message")
String message;

public String getMessage() {
    return message;
}

public void setMessage(String message) {
    this.message = message;
}

@FormUrlEncoded
@POST("user/send/request")
Call<BookingResponse> getServiceBooked(@Field("s_latitude") String latitude, @Field("s_longitude") String longitude,
                                       @Field("service_type") String serviceType, @Field("payment_mode") String payment,
                                       @Field("schedule_date") String date, @Field("schedule_time") String scheduleTime,
                                       @Field("s_address") String address, @FieldMap HashMap<String, String> questions,
                                       @Field("question[]") String[] mainList);

0 个答案:

没有答案