使用翻新和rxjava2时显示JSON文档未完全消耗的异常

时间:2019-09-14 07:33:53

标签: android retrofit2 rx-java2

我正在使用改造和rxjava2将数据保存到数据库中的数据已成功添加,但是下面显示了异常:

./target/release/node-name

即使没有错误并且我的数据已成功添加到数据库中,为什么也会显示此异常。添加数据后,我想显示服务器发送的成功消息,但添加数据后显示的是异常消息,而不是成功的消息。

在服务器中成功显示来自服务器的POST请求消息后,我尝试用Postman尝试api。

下面是我的代码:

ApiService.class

JSON document was not fully consumed

RetrofitClient.class

public interface ApiService {

@POST("saveData")
@FormUrlEncoded
Single<String> saveDataOnServer(@Field("Name") String Name,
                                @Field("Age") String Age);

}

Employee.java

public class RetrofitClient {

private static Retrofit retrofit = null;

private static final String URL = "https://example.com/";

public static Retrofit getInstance(){

    OkHttpClient okHttpClient = new OkHttpClient.Builder()
                                .connectTimeout(10, TimeUnit.SECONDS)
                                .readTimeout(10,TimeUnit.SECONDS)
                                .writeTimeout(10,TimeUnit.SECONDS)
                                .build();

    if(retrofit == null){

        retrofit = new Retrofit.Builder()
                       .baseUrl(URL)
                       .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                       .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
                       .client(okHttpClient)
                       .build();
    }

    return retrofit;
  }

private RetrofitClient(){

  }

}    

AddEmploy.class

public class Employee {

@SerializedName("Name")
@Expose
String Name;

@SerializedName("Age")
@Expose
String Age;

public Employee(){

}

public Employee(String Name,String Age){

    this.Name = Name;
    this.Age = Age;
}

public String getName() {
    return Name;
}

public void setName(String name) {
    Name = name;
}

public String getAge() {
    return Age;
}

public void setAge(String age) {
    Age = age;
}
}

Repository.class

public class AddEmploy extends AppCompatActivity {

ActivityAddEmployBinding activityAddEmployBinding;
Repository repo;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_employ);

    activityAddEmployBinding = DataBindingUtil.setContentView(this,R.layout.activity_add_employ);

    activityAddEmployBinding.setAddButton(this);

    repo = new Repository(this);

}

public void add(View view){

repo.addEmployee(activityAddEmployBinding.name.getText().toString(),activityAddEmployBinding.age.getText().toString());

   }
 }

请让我知道为什么显示此异常。我们将不胜感激。

谢谢

0 个答案:

没有答案