Count of objects in JSON (UWP C#) -
i writing app windows 10.
i have using woocommerce.net plugin download data worspress site.
i download this.
restapi rest = new restapi("http://simplegames.com.ua/wp-json/wc/v1/", "ck_9d64c027d2c5f81b8bed3342eeccc6d337be813d", "cs_60697b1e6cbdeb8d62d19e0765e339f8e3334754"); wcobject wc = new wcobject(rest); //get products var orders = await wc.getorders(); var products = orders[0].line_items;
{ "id": 1897, "parent_id": 0, "status": "processing", "order_key": "wc_order_57cec87491975", "currency": "uah", "version": "2.6.4", "prices_include_tax": false, "date_created": "2016-09-06t13:45:24", "date_modified": "2016-09-06t13:45:24", "customer_id": 0, "discount_total": 0.00, "discount_tax": 0.00, "shipping_total": 0.00, "shipping_tax": 0.00, "cart_tax": 0.00, "total": 140.00, "total_tax": 0.00, "billing": { "first_name": "Евгений", "last_name": "Сухомлин", "company": "", "address_1": "sdfsdf", "address_2": "sdfsdfsdfdf", "city": "", "state": "", "postcode": "", "country": "", "email": "nemesises@live.com", "phone": "3904354345" }, "shipping": { "first_name": "Евгений", "last_name": "Сухомлин", "company": "", "address_1": "sdfsdf", "address_2": "sdfsdfsdfdf", "city": "", "state": "", "postcode": "", "country": "" }, "payment_method": "cod", "payment_method_title": "Оплата готівкою", "transaction_id": "", "customer_ip_address": "46.133.88.220", "customer_user_agent": "mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, gecko) chrome/52.0.2743.116 safari/537.36", "created_via": "checkout", "customer_note": "", "date_completed": "2016-09-06t16:45:24", "date_paid": "", "cart_hash": "187385bf4fb75116424e9cfeb1aa9ccd", "line_items": [ { "id": 75, "name": "Сформуй сам", "sku": "", "product_id": 1271, "variation_id": 0, "quantity": 1, "tax_class": "", "price": 40.00, "subtotal": 40.00, "subtotal_tax": 0.00, "total": 40.00, "total_tax": 0.00, "taxes": [ ], "meta": [ { "key": "Розмір піци (обов'язково) <span class=\"woocommerce-price-amount amount\">40 <span class=\"woocommerce-price-currencysymbol\">грн</span></span>", "label": "Розмір піци (обов'язково) <span class=\"woocommerce price amount amount\">40 <span class=\"woocommerce price currencysymbol\">грн</span></span>", "value": "Піца база велика (380г)" } ] }, { "id": 76, "name": "Сформуй сам", "sku": "", "product_id": 1271, "variation_id": 0, "quantity": 1, "tax_class": "", "price": 100.00, "subtotal": 100.00, "subtotal_tax": 0.00, "total": 100.00, "total_tax": 0.00, "taxes": [ ], "meta": [ { "key": "Розмір піци (обов'язково) <span class=\"woocommerce-price-amount amount\">30 <span class=\"woocommerce-price-currencysymbol\">грн</span></span>", "label": "Розмір піци (обов'язково) <span class=\"woocommerce price amount amount\">30 <span class=\"woocommerce price currencysymbol\">грн</span></span>", "value": "Піца база мала (280г)" }, { "key": "Ананас (9грн) <span class=\"woocommerce-price-amount amount\">9 <span class=\"woocommerce-price-currencysymbol\">грн</span></span>", "label": "Ананас (9грн) <span class=\"woocommerce price amount amount\">9 <span class=\"woocommerce price currencysymbol\">грн</span></span>", "value": "1" }, { "key": "Балик (11грн) <span class=\"woocommerce-price-amount amount\">11 <span class=\"woocommerce-price-currencysymbol\">грн</span></span>", "label": "Балик (11грн) <span class=\"woocommerce price amount amount\">11 <span class=\"woocommerce price currencysymbol\">грн</span></span>", "value": "1" }, { "key": "Бекон (9грн) <span class=\"woocommerce-price-amount amount\">9 <span class=\"woocommerce-price-currencysymbol\">грн</span></span>", "label": "Бекон (9грн) <span class=\"woocommerce price amount amount\">9 <span class=\"woocommerce price currencysymbol\">грн</span></span>", "value": "1" }, { "key": "Свинина вялена (12грн) <span class=\"woocommerce-price-amount amount\">12 <span class=\"woocommerce-price-currencysymbol\">грн</span></span>", "label": "Свинина вялена (12грн) <span class=\"woocommerce price amount amount\">12 <span class=\"woocommerce price currencysymbol\">грн</span></span>", "value": "1" }, { "key": "Зелень (4грн) <span class=\"woocommerce-price-amount amount\">4 <span class=\"woocommerce-price-currencysymbol\">грн</span></span>", "label": "Зелень (4грн) <span class=\"woocommerce price amount amount\">4 <span class=\"woocommerce price currencysymbol\">грн</span></span>", "value": "1" }, { "key": "Копчене куряче філе (10грн) <span class=\"woocommerce-price-amount amount\">10 <span class=\"woocommerce-price-currencysymbol\">грн</span></span>", "label": "Копчене куряче філе (10грн) <span class=\"woocommerce price amount amount\">10 <span class=\"woocommerce price currencysymbol\">грн</span></span>", "value": "1" }, { "key": "Крабові палички (11грн) <span class=\"woocommerce-price-amount amount\">11 <span class=\"woocommerce-price-currencysymbol\">грн</span></span>", "label": "Крабові палички (11грн) <span class=\"woocommerce price amount amount\">11 <span class=\"woocommerce price currencysymbol\">грн</span></span>", "value": "1" }, { "key": "Кукурудза консервована (4грн) <span class=\"woocommerce-price-amount amount\">4 <span class=\"woocommerce-price-currencysymbol\">грн</span></span>", "label": "Кукурудза консервована (4грн) <span class=\"woocommerce price amount amount\">4 <span class=\"woocommerce price currencysymbol\">грн</span></span>", "value": "1" } ] } ], "tax_lines": [ ], "shipping_lines": [ { "id": 77, "method_title": "Безкоштовна доставка", "method_id": "free_shipping:5", "total": 0.00, "total_tax": 0.00, "taxes": [ ] } ], "fee_lines": [ ], "coupon_lines": [ ] }
in line_items can have many objects.
i tried using json.net plugin newtosoft, not works.
jarray items = (jarray)test["jsonobject"]; int length = items.count; (int = 0; < items.count; i++) { var item = (jobject)items[i]; //do item }`
how can count them , display in console example name
field of each?
i solved problem.
code did trick.
jarray jobj = (jarray)jsonconvert.deserializeobject(products); int count = jobj.count; debug.writeline(count);
Comments
Post a Comment