кто хорошо разбирается в javascript ? нужна помощь

artsmm

Client
Регистрация
03.10.2018
Сообщения
1 136
Благодарностей
196
Баллы
63
есть массив json:
JSON:
{"state":0,"params":{"version":2,"curr":"rub","spp":29,"dest":-1257786,"payloadVersion":1},"data":{"products":[{"id":177981298,"root":162378055,"kindId":0,"brand":"BAUHAUS","brandId":152248,"siteBrandId":162248,"colors":[{"name":"черный","id":0}],"subjectId":2678,"subjectParentId":1521,"name":"Аэрогриль электрический","supplier":"Товары для дома","supplierId":1374968,"supplierRating":4.8,"supplierFlags":0,"priceU":1187300,"salePriceU":632500,"logisticsCost":0,"sale":46,"returnCost":0,"diffPrice":false,"saleConditions":0,"pics":27,"rating":5,"reviewRating":4.8,"feedbacks":867,"volume":532,"viewFlags":16,"promotions":[63484,92742,162613,163950],"sizes":[{"name":"","origName":"0","rank":0,"optionId":294655729,"returnCost":0,"stocks":[{"wh":2737,"dtype":4,"qty":1,"priority":51569,"time1":4,"time2":52},{"wh":507,"dtype":4,"qty":123,"priority":85911,"time1":4,"time2":26},{"wh":120762,"dtype":4,"qty":86,"priority":80262,"time1":7,"time2":27},{"wh":206348,"dtype":4,"qty":14,"priority":84019,"time1":1,"time2":30},{"wh":117986,"dtype":4,"qty":112,"priority":50785,"time1":3,"time2":53}],"time1":4,"time2":26,"wh":507,"dtype":4,"sign":"MRq7MIgoZynbA73PWuGVg+l4xTY=","payload":"lfTuZXLHmwrxFpARQ/ZYtTBd9INplbOcq2+e3x5B8Kn8qlU4/cVrBBYKuBITZscFgb6ysqOdDg"}],"time1":4,"time2":26,"wh":507,"dtype":4}]}}
мне нужно получить из него все значения qty (только их).
Можете подсказать как это сделать на javascript ? gpt не справляется ))
в идеале нужен код для google script
 

n0n3mi1y

Client
Регистрация
08.03.2017
Сообщения
1 237
Благодарностей
573
Баллы
113
Плохо спрашиваешь)
gpt не справляется ))
JavaScript:
// Ваш JSON-объект
var jsonData = '{"state":0,"params":{"version":2,"curr":"rub","spp":29,"dest":-1257786,"payloadVersion":1},"data":{"products":[{"id":177981298,"root":162378055,"kindId":0,"brand":"BAUHAUS","brandId":152248,"siteBrandId":162248,"colors":[{"name":"черный","id":0}],"subjectId":2678,"subjectParentId":1521,"name":"Аэрогриль электрический","supplier":"Товары для дома","supplierId":1374968,"supplierRating":4.8,"supplierFlags":0,"priceU":1187300,"salePriceU":632500,"logisticsCost":0,"sale":46,"returnCost":0,"diffPrice":false,"saleConditions":0,"pics":27,"rating":5,"reviewRating":4.8,"feedbacks":867,"volume":532,"viewFlags":16,"promotions":[63484,92742,162613,163950],"sizes":[{"name":"","origName":"0","rank":0,"optionId":294655729,"returnCost":0,"stocks":[{"wh":2737,"dtype":4,"qty":1,"priority":51569,"time1":4,"time2":52},{"wh":507,"dtype":4,"qty":123,"priority":85911,"time1":4,"time2":26},{"wh":120762,"dtype":4,"qty":86,"priority":80262,"time1":7,"time2":27},{"wh":206348,"dtype":4,"qty":14,"priority":84019,"time1":1,"time2":30},{"wh":117986,"dtype":4,"qty":112,"priority":50785,"time1":3,"time2":53}],"time1":4,"time2":26,"wh":507,"dtype":4,"sign":"MRq7MIgoZynbA73PWuGVg+l4xTY=","payload":"lfTuZXLHmwrxFpARQ/ZYtTBd9INplbOcq2+e3x5B8Kn8qlU4/cVrBBYKuBITZscFgb6ysqOdDg"}],"time1":4,"time2":26,"wh":507,"dtype":4}]}}'; // Замените {...} на ваш JSON-объект

// Парсим JSON
var parsedData = JSON.parse(jsonData);

// Извлечение значений qty из массива stocks
var products = parsedData.data.products;
var qtyValues = [];

products.forEach(product => {
    product.sizes.forEach(size => {
        size.stocks.forEach(stock => {
            qtyValues.push(stock.qty);
        });
    });
});

console.log(qtyValues); // Вывод массива значений qty
 

artsmm

Client
Регистрация
03.10.2018
Сообщения
1 136
Благодарностей
196
Баллы
63

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)