如何在不使用null的情况下获取数组值:Retrofit Android

时间:2017-11-16 08:15:20

标签: android retrofit retrofit2

我正在使用改装进行服务调用。返回5个数据集。每个数据集包含6个值。每个数据集包含一个实际值,其他数据集为null。何时可以获得没有空值的实际值?

POST人的反应就像吼叫

{
    "status": true,
    "message": "successfully count new orders",
    "data": [
        {
            "order_count": "3"
        },
        {
            "pending_order": "0"
        },
        {
            "schedule": "2017-11-18 12:00",
            "id_order": "272",
            "reference": "KB-838704"
        },
        {
            "deli_orders": "0"
        },
        {
            "store_count": "0"
        }
    ]
}

网络服务电话

 WebserviceAPI apiService =retrofit.create(WebserviceAPI.class);
            Call<OrderResponse> call = apiService.getSummery("countnew",token_acces);
            call.enqueue(new Callback<OrderResponse>() {
                @Override
                public void onResponse(Call<OrderResponse> call, Response<OrderResponse> response) {
                    OrderResponse result = response.body();
                    List<Order> data=result.getData();
                    status=result.isStatus();
                    msg= result.getMessage();

                    for (Order a:data)
                    {
                        try {
                            Log.d("ress",""+a.getOrder_count()+" : "+a.getPending_order()+" : "+a.getReference()
                            +" : "+a.getSchedule()+" : "+a.getDeli_orders()+" : "+a.getStore_count());

                        //update

                           if( !(a.getOrder_count().contentEquals("null"))){
                            Log.d("ress","new order "+a.getOrder_count());
                            //txtNewOrder.setText(a.getOrder_count());
                        }
                        if( !(a.getPending_order().contentEquals("null"))){
                            Log.d("ress","pending "+a.getPending_order());
                           // txtPendingOrder.setText(a.getPending_order());
                        }
                        if( !(a.getReference().contentEquals("null"))){
                            Log.d("ress","reference "+a.getReference());
                            //txtRecentOrder.setText(a.getReference());
                        }
                        if( !(a.getSchedule().contentEquals("null"))){
                            Log.d("ress","time "+a.getSchedule());
                            //txtRemainingTime.setText(a.getSchedule());
                        }
                        if( !(a.getDeli_orders().contentEquals("null"))){
                            Log.d("ress"," delivered "+a.getDeli_orders());
                            //txtDeliveredOrder.setText(a.getDeli_orders());
                        }
                        if( !(a.getStore_count().contentEquals("null"))){
                            Log.d("ress","store "+a.getStore_count());
                            //txtStoreOrder.setText(a.getStore_count());
                        }


                        }catch (NullPointerException e){

                        }
                    }

                }

                @Override
                public void onFailure(Call<OrderResponse> call, Throwable t) {
                    Log.d("fragres",""+t.getMessage());

                }
            });

更新:Order.java

public class Order {

    String order_count;
    String pending_order;
    String schedule;
    String id_order;
    String reference;
    String deli_orders;
    String store_count;


    public String getOrder_count() {
        return order_count;
    }

    public void setOrder_count(String order_count) {
        this.order_count = order_count;
    }

    public String getPending_order() {
        return pending_order;
    }

    public void setPending_order(String pending_order) {
        this.pending_order = pending_order;
    }

    public String getSchedule() {
        return schedule;
    }

    public void setSchedule(String schedule) {
        this.schedule = schedule;
    }

    public String getId_order() {
        return id_order;
    }

    public void setId_order(String id_order) {
        this.id_order = id_order;
    }

    public String getReference() {
        return reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    public String getDeli_orders() {
        return deli_orders;
    }

    public void setDeli_orders(String deli_orders) {
        this.deli_orders = deli_orders;
    }

    public String getStore_count() {
        return store_count;
    }

    public void setStore_count(String store_count) {
        this.store_count = store_count;
    }



}

logcat的

enter image description here

当我在for循环中检查null时,它只显示第一个值(num 3)

我想得到:

来自1个数据集的第1个值,来自第2个数据集的第2个值,来自3个数据集的第3个和第4个值,来自第4个数据集的第5个值,来自第5个数据集的第6个值

0 个答案:

没有答案