【发布时间】:2018-07-16 07:26:35
【问题描述】:
我正在尝试将 json 数据发布到服务器,但未调用 call.enqueue onResponse 和 onFailure。
这是我要发布到服务器的 Json 数据类型。
{"ClientId":16,
"CityId":1,
"TotalCheque":2,
"Cheques":[
{
"ChequeAmount": 15000,
"ChequeNumber":205,
"ChequeDate": "11/7/18",
"ChequeImage":"www/ass/img10111"
},
{
"ChequeAmount": 21000,
"ChequeNumber":297,
"ChequeDate": "14/7/18",
"ChequeImage":"www/ass/img10111"
}
]}
这是我的数据的模态类。
public class AllCheques {
@SerializedName("ClientId")
@Expose
public Integer clientid;
@SerializedName("CityId")
@Expose
public Integer cityid;
@SerializedName("TotalCheque")
@Expose
public Integer totalcheque;
@SerializedName("Cheques")
@Expose
public ArrayList<Cheque_Payment> cheques;
public AllCheques(Integer cityid , Integer clientid , Integer totalcheque ,ArrayList<cheques> chequesall){
this.cityid = cityid;
this.clientid = clientid;
this.totalcheque =totalcheque;
this.chequesall = chequesall;
}
public Integer getCityId() {
return cityid ;
}
public void setCityId(Integer cityid ) {
this.cityid = cityid;
}
public Integer getClientId() {
return clientid;
}
public void setClientId(Integer clientid) {
this.clientid = clientid;
}
public Integer getTotalcheque() {
return totalcheque ;
}
public void setTotalcheque(Integer totalcheque) {
this.totalcheque = totalcheque;
}
public ArrayList<cheques> chequesall = new ArrayList<>();
public ArrayList<cheques> getChequesall() {
return chequesall;
}
public void setChequesall(ArrayList<cheques> chequesall )
{
this.chequesall = chequesall;
}
public static class cheques{
@SerializedName("ChequeAmount")
@Expose
public Integer chequeAmount;
@SerializedName("ChequeNumber")
@Expose
public Integer chequeNumber;
@SerializedName("ChequeDate")
@Expose
public String chequeDate;
@SerializedName("ChequeImage")
@Expose
public String chequeImage;
public cheques( Integer chequeAmount , Integer chequeNumber ,String chequeDate, String chequeImage)
{
this.chequeAmount = chequeAmount;
this.chequeNumber = chequeNumber;
this.chequeDate = chequeDate;
this.chequeImage = chequeImage;
}
public cheques() {
}
public Integer getChequeAmount() {
return chequeAmount ;
}
public void setChequeAmount(Integer chequeAmount) {
this.chequeAmount =chequeAmount;
}
public Integer getChequeNumber() {
return chequeNumber ;
}
public void setChequeNumber(Integer chequeNumber) {
this.chequeNumber =chequeNumber;
}
public String getChequeDate() {
return chequeDate ;
}
public void setChequeImage(String chequeImage) {
this.chequeImage =chequeImage;
}
public String getChequeImage() {
return chequeImage ;
}
}
}
在这里的活动中,我试图在 callx.enqueue 中调用响应和失败 我已收到这些变量中的数据。
public void send_info()
{
CityID = Integer.parseInt(selectedId);
ClientID = Integer.parseInt(cclient_id);
TotalCheques = val;
addcheque_tolist();
//this give chequeslist
//here i get all data now calling
ApiInterface = ApiClient.getApiClient().create(Api.class);
Call<CHQ> callx = ApiInterface.SaveCheques(CityID,ClientID,TotalCheques,chequeslist);
callx.enqueue(new Callback<CHQ>() {
@Override
public void onResponse(Call<CHQ> callx, Response<CHQ> response) {
if (response.isSuccessful()) {
String data = response.body().toString();
Toast.makeText(Recieve_Payment.this, response.body().getMsg().toString(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<CHQ> callx, Throwable t) {
}
});
//here on response and on failure does not debug or pass.
}
}
在 Api 接口中
@FormUrlEncoded
@POST("dummy_chequedata.php")
Call<CHQ> SaveCheques(@Field("clientid") Integer ClientID,
@Field("cityid") Integer CityID,
@Field("totalcheque") Integer TotalCheques,
@Field("chequeslist[]")ArrayList<AllCheques.cheques> chequeslist
);
【问题讨论】:
-
你有没有在你的 onFailure 中放任何日志或任何东西?
-
在 onresponse 或失败中没有得到任何日志它没有进入 onresponse 或 onfailure 直接结束该方法。