我遇到了使用改装库获取响应的问题。 我的JSON低于
{
"regData": [
{
"registrationType": "User",
"userDetails": {
"city": "Bangalore ",
"country": "Bangalore ",
"email": "hfhg@lll.com",
"name": "Cxhcc",
"password": "123456",
"phoneno": "486586"
},
"vehicleRegsiration": {}
}
]
}
请注意,在调试我的应用程序之后我得到了json,当我使用与邮递员休息客户端应用程序相同的JSON时,它工作正常。
以下是我的代码
public void postRegistrationData(Registeration reqBody){
ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
Call<Long> call = apiService.registrationApi(reqBody);
call.enqueue(new Callback<Long>() {
@Override
public void onResponse(Call<Long> call, Response<Long> response) {
if(response.isSuccessful()){
Long id = response.body().longValue();
Log.d(TAG, "Response: " + id);
} else{
Log.d(TAG, "Response failed: ");
}
}
@Override
public void onFailure(Call<Long>call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
执行上面的代码后,它总是执行下面的代码
Log.d(TAG,“响应失败:”);
public Registeration prepareRegRequestBody(UserDetails uDetail , VehicleRegsiration vDedail, String regType){
RegDatum reg = new RegDatum();
List<RegDatum> regList = new ArrayList<RegDatum>();
Registeration regUV = new Registeration();
reg.setRegistrationType(regType);
reg.setUserDetails(uDetail);
reg.setVehicleRegsiration(vDedail);
regList.add(reg);
regUV.setRegData(regList);
return regUV;
}
public Registeration inputDataUV(){
UserDetails userDetail = new UserDetails();
VehicleRegsiration vehicleRegsiration = new VehicleRegsiration();
Registeration reqbody = new Registeration();
if(userType.getSelectedItem().toString().equalsIgnoreCase("User")){
userDetail.setEmail(signupInputEmail.getText().toString());
userDetail.setPassword(signupInputPassword.getText().toString());
userDetail.setPhoneno(signupInputMobile.getText().toString());
userDetail.setName(signupInputName.getText().toString());
userDetail.setCountry(countryName1.getText().toString());
userDetail.setCity(signupInputCity.getText().toString());
reqbody = prepareRegRequestBody(userDetail, vehicleRegsiration, "User" );
return reqbody;
} else if(userType.getSelectedItem().toString().equalsIgnoreCase("Vehicle")){
vehicleRegsiration.setVehicleOwner(vSignupEmailId.getText().toString());
vehicleRegsiration.setVehicleNoPlate(vSignupVnumber.getText().toString());
vehicleRegsiration.setVehicleType(vSignupType.getText().toString());
vehicleRegsiration.setImeiNo(Long.parseLong(vSignupImeiNo.getText().toString()));
vehicleRegsiration.setPassword(vSignupPassword.getText().toString());
vehicleRegsiration.setCountry(vcountryName1.getText().toString());
vehicleRegsiration.setCity(vSignupCity.getText().toString());
reqbody = prepareRegRequestBody(userDetail, vehicleRegsiration, "Vehicle" );
return reqbody;
} else{
return reqbody;
}
}
我做错了,请帮我摆脱这个问题。