Как опубликовать список с JSONObject в Android, используя залп - PullRequest
0 голосов
/ 05 октября 2018

Я - приложение для Android, в котором я отправляю объект json на сервер. Я отправляю массив с этим объектом, названным listProduct, а также отправляю второй массив в списке listProduct.Мой код как:

final JSONObject object = new JSONObject();
    try {
        object.put("AddressID",addressId);
        object.put("CustomerID",customerID);
        object.put("PaymentTypeID",paymentTypeID);
        ///////////////////////////////////////////////
        JSONArray productArray = new JSONArray();
        JSONObject productObject = new JSONObject();
        for (int i=0;i<products.size;i++){
        productObject.put("ProductID",productID);
        productObject.put("Price",price);
        productObject.put("Quantity",quantity);
        productArray.put(productObject);
        }
        object.put("ListProducts",productArray);
        ///////////////////////////////////////////////
        JSONArray attributeArray = new JSONArray();
        JSONObject attributeObject = new JSONObject();
        for (int i=0;i<attributes.size;i++){
        attributeObject.put("Name",name);
        attributeObject.put("ProductID",productID);
        attributeObject.put("AttributeTypeID",attributeTypeId);
        attributeObject.put("AttributeID",attributeId);
        attributeArray.put(attributeObject);

        }
        productObject.put("ListAttributes",attributeArray);

и вот мой список продуктов, который поступает из базы данных sqlite.проблема в том, что одно и то же значение отправляется снова и снова на сервер.как я могу отправить полный массив на сервер с индексами.

private ArrayList<Integer> getCheckProduct() {
    Cursor cursor = dbHelper.getCheckOutProduct();
    products = new ArrayList<>();
    if (cursor != null && cursor.getCount() > 0) {
        Log.e("count",String.valueOf(cursor.getCount()));
        while (cursor.moveToNext()) {
            autoProductID = cursor.getInt(cursor.getColumnIndex("ID"));
            price = cursor.getInt(cursor.getColumnIndex("Price"));
            quantity = cursor.getInt(cursor.getColumnIndex("Quantity"));
            productID = cursor.getInt(cursor.getColumnIndex("ProductID"));
            products.add(productID);
        }
    }
    return products;
}
...