/
nonamerz
/
sandbox
Обзор
Документация
Войти
/
nonamerz
/
sandbox
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/main/java/JsonConstructor.java
39 строк
1 KB
nonamerz
Сборка корзины с добавлением товаров имеющих свои параметры
11 дек 2024, 00:38
11 дек 2024, 00:38
496f673
Код
Авторство
О чём код?
import org.json.*; public class JsonConstructor { private JSONObject cart; private JSONArray items; public JsonConstructor(){ cart = new JSONObject(); items = new JSONArray(); } public void buildEmptyCart(){ cart.put("positions", JSONObject.NULL); cart.put("totalAmount", JSONObject.NULL); cart.put("name", JSONObject.NULL); cart.put("description", JSONObject.NULL); cart.put("items", items); } public void buildCart(String name, int totalAmount, String description){ cart.put("name", name); cart.put("amount", totalAmount); cart.put("description", description); cart.put("items", items); } public void addCartItem(String name, int amount, String description){ JSONObject item = new JSONObject(); item.put("name", name); item.put("amount", amount); item.put("description", description); items.put(item); } public String getCartAsString() { return cart.toString(); } }