bugfix> android > 投稿

nullでステータス200を取得するリクエストレスポンス本文を投稿すると?

私が間違っているのは何ですか?

ここに私の呼び出し方法があります

 private void getTransferBtwCenterAndOffice(){
    showProgressDialog(getString(R.string.wait_message));
    ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
    String userName = tinyDb.getString(Constant.userName);
    String passWord = tinyDb.getString(Constant.token);
    List<TransferCenterStoreParameters> parameters = new ArrayList<>();
    parameters.add(new TransferCenterStoreParameters("StoreCode","B201"));
    String base = userName + ":" + passWord;
    String authHeader = "Basic "+ Base64.encodeToString(base.getBytes(),Base64.NO_WRAP);
    Call<TransferCenterStoreResponse> call = apiService.TRANSFER_CENTER_STORE_RESPONSE_CALL(authHeader,"BR_SP_BRN_GET_STORE_ACTIVE_SHIPMENTS",parameters);
    call.enqueue(new Callback<TransferCenterStoreResponse>() {
        @Override
        public void onResponse(Call<TransferCenterStoreResponse> call, retrofit2.Response<TransferCenterStoreResponse> response) {
            hideProgressDialog();
            Log.d(CLASS_NAME, "onResponseeeeeeeee: "+response);
            if(response != null && response.body() != null){
                if(response.body().getTransferBtwCenterStoreResult().getResultCode().equals("200")){
                    List<TransferCenterStore> mList = response.body().getTransferCenterStoresList();
                }
                else{
                    getAlert(response.body().getTransferBtwCenterStoreResult().getErrorMessage());
                }
            }
        }
        @Override
        public void onFailure(Call<TransferCenterStoreResponse> call, Throwable t) {
            hideProgressDialog();
            Log.e(CLASS_NAME, t.toString());
        }
    });
}

ここに私のapiinterfaceがあります

@FormUrlEncoded
    @POST("GetDispatchList")
    Call<TransferCenterStoreResponse> TRANSFER_CENTER_STORE_RESPONSE_CALL(
            @Header("Authorization") String authHeader,
            @Field("ProcName") String procName,
            @Field("Parameters") List<TransferCenterStoreParameters> objects) ;

ここに私のパラメーター本体があります 

{ "ProcName" :"BR_SP_BRN_GET_STORE_ACTIVE_SHIPMENTS", "Parameters": [ { "Name": "StoreCode", "Value": "B201" } ] }

ここに私のtransfercenterstoreresponseクラスがあります

public class TransferCenterStoreResponse {
    @SerializedName("ResultModel")
    private TransferBtwCenterStoreResult transferBtwCenterStoreResult;
    @SerializedName("Dispatches")
    private List<TransferCenterStore> transferCenterStoresList;

    public TransferBtwCenterStoreResult getTransferBtwCenterStoreResult() {
        return transferBtwCenterStoreResult;
    }
    public void setTransferBtwCenterStoreResult(TransferBtwCenterStoreResult transferBtwCenterStoreResult) {
        this.transferBtwCenterStoreResult = transferBtwCenterStoreResult;
    }
    public List<TransferCenterStore> getTransferCenterStoresList() {
        return transferCenterStoresList;
    }
    public void setTransferCenterStoresList(List<TransferCenterStore> transferCenterStoresList) {
        this.transferCenterStoresList = transferCenterStoresList;
    }
}

ここに私の応答があります 

{
    "ResultModel": {
        "ResultStatus": "Success",
        "ResultCode": "200",
        "ErrorMessage": null,
        "Token": "BD0F1E3D1F8E43B79BCE96FA6572A2AD",
        "ResultJson": "",
        "ConnectionUrl": "http://192.168.3.40:1313/",
        "UserName": null,
        "ResultNative": "",
        "ResultDt": null
    },
    "Dispatches": [
        {
            "ShippingNumber": "178-S-6-30770",
            "ShippingDate": "2018-02-11T21:00:00Z",
            "Description": "",
            "InternalDescription": "",
            "SeriesNumber": 322216,
            "LogisticsCompanyBOL": "",
            "WarehouseCode": "B456",
            "ShipmentHeaderID": "3408fcec-9e8f-4e82-b556-a88500d3713f",
            "Quantitity": 1
        }
]
}

回答 1 件
  • 200を取得し、サーバーからjsonデータを取得する場合、応答pojoクラスがすべてサーバーのjsonキーと同じキーであることを確認してください。

    以下のようにpojoクラスを確認してください。

    public class DispatchesItem{
    private String description;
    private int quantitity;
    private String shippingNumber;
    private String shippingDate;
    private int seriesNumber;
    private String shipmentHeaderID;
    private String internalDescription;
    private String warehouseCode;
    private String logisticsCompanyBOL;
    public void setDescription(String description){
        this.description = description;
    }
    public String getDescription(){
        return description;
    }
    public void setQuantitity(int quantitity){
        this.quantitity = quantitity;
    }
    public int getQuantitity(){
        return quantitity;
    }
    public void setShippingNumber(String shippingNumber){
        this.shippingNumber = shippingNumber;
    }
    public String getShippingNumber(){
        return shippingNumber;
    }
    public void setShippingDate(String shippingDate){
        this.shippingDate = shippingDate;
    }
    public String getShippingDate(){
        return shippingDate;
    }
    public void setSeriesNumber(int seriesNumber){
        this.seriesNumber = seriesNumber;
    }
    public int getSeriesNumber(){
        return seriesNumber;
    }
    public void setShipmentHeaderID(String shipmentHeaderID){
        this.shipmentHeaderID = shipmentHeaderID;
    }
    public String getShipmentHeaderID(){
        return shipmentHeaderID;
    }
    public void setInternalDescription(String internalDescription){
        this.internalDescription = internalDescription;
    }
    public String getInternalDescription(){
        return internalDescription;
    }
    public void setWarehouseCode(String warehouseCode){
        this.warehouseCode = warehouseCode;
    }
    public String getWarehouseCode(){
        return warehouseCode;
    }
    public void setLogisticsCompanyBOL(String logisticsCompanyBOL){
        this.logisticsCompanyBOL = logisticsCompanyBOL;
    }
    public String getLogisticsCompanyBOL(){
        return logisticsCompanyBOL;
    }
    @Override
    public String toString(){
        return 
            "DispatchesItem{" + 
            "description = '" + description + '\'' + 
            ",quantitity = '" + quantitity + '\'' + 
            ",shippingNumber = '" + shippingNumber + '\'' + 
            ",shippingDate = '" + shippingDate + '\'' + 
            ",seriesNumber = '" + seriesNumber + '\'' + 
            ",shipmentHeaderID = '" + shipmentHeaderID + '\'' + 
            ",internalDescription = '" + internalDescription + '\'' + 
            ",warehouseCode = '" + warehouseCode + '\'' + 
            ",logisticsCompanyBOL = '" + logisticsCompanyBOL + '\'' + 
            "}";
        }
    }
    
    public class ResultModel{
    private String resultJson;
    private Object userName;
    private String resultStatus;
    private String connectionUrl;
    private String token;
    private String resultNative;
    private Object resultDt;
    private Object errorMessage;
    private String resultCode;
    public void setResultJson(String resultJson){
        this.resultJson = resultJson;
    }
    public String getResultJson(){
        return resultJson;
    }
    public void setUserName(Object userName){
        this.userName = userName;
    }
    public Object getUserName(){
        return userName;
    }
    public void setResultStatus(String resultStatus){
        this.resultStatus = resultStatus;
    }
    public String getResultStatus(){
        return resultStatus;
    }
    public void setConnectionUrl(String connectionUrl){
        this.connectionUrl = connectionUrl;
    }
    public String getConnectionUrl(){
        return connectionUrl;
    }
    public void setToken(String token){
        this.token = token;
    }
    public String getToken(){
        return token;
    }
    public void setResultNative(String resultNative){
        this.resultNative = resultNative;
    }
    public String getResultNative(){
        return resultNative;
    }
    public void setResultDt(Object resultDt){
        this.resultDt = resultDt;
    }
    public Object getResultDt(){
        return resultDt;
    }
    public void setErrorMessage(Object errorMessage){
        this.errorMessage = errorMessage;
    }
    public Object getErrorMessage(){
        return errorMessage;
    }
    public void setResultCode(String resultCode){
        this.resultCode = resultCode;
    }
    public String getResultCode(){
        return resultCode;
    }
    @Override
    public String toString(){
        return 
            "ResultModel{" + 
            "resultJson = '" + resultJson + '\'' + 
            ",userName = '" + userName + '\'' + 
            ",resultStatus = '" + resultStatus + '\'' + 
            ",connectionUrl = '" + connectionUrl + '\'' + 
            ",token = '" + token + '\'' + 
            ",resultNative = '" + resultNative + '\'' + 
            ",resultDt = '" + resultDt + '\'' + 
            ",errorMessage = '" + errorMessage + '\'' + 
            ",resultCode = '" + resultCode + '\'' + 
            "}";
        }
      }
    
    

    そしてあなたの応答クラス

    public class Response{
    @SerializedName("Dispatches")
    private List<DispatchesItem> dispatches;
    @SerializedName("ResultModel")
    private ResultModel resultModel;
    public void setDispatches(List<DispatchesItem> dispatches){
        this.dispatches = dispatches;
    }
    public List<DispatchesItem> getDispatches(){
        return dispatches;
    }
    public void setResultModel(ResultModel resultModel){
        this.resultModel = resultModel;
    }
    public ResultModel getResultModel(){
        return resultModel;
    }
    @Override
    public String toString(){
        return 
            "Response{" + 
            "dispatches = '" + dispatches + '\'' + 
            ",resultModel = '" + resultModel + '\'' + 
            "}";
        }
    
    

    }

    @SerializedName( "json key")の上のすべてのpojoクラスフィールドをjsonキーに入れます。

あなたの答え