0

I writing app for Windows 10.

I have connection with WooCommerce with WooCommerce.Net plugin

Here it is plugin

I have JSON string.

Code:

RestAPI rest = new RestAPI("http://simplegames.com.ua/wp-json/wc/v1/", "ck_9d64c027d2c5f81b8bed3342eeccc6d337be813d", "cs_60697b1e6cbdeb8d62d19e0765e339f8e3334754");
        WCObject wc = new WCObject(rest);
        //Получение заказов
        var orders = await wc.GetOrders()
 string products = orders[1].line_items.ToFormattedJsonString();
  Debug.WriteLine(products);

I have this JSON in Console

[
  {
    "id": 72,
    "name": "Із лосося",
    "sku": "344",
    "product_id": 1134,
    "variation_id": 0,
    "quantity": 1,
    "tax_class": "",
    "price": 75.00,
    "subtotal": 75.00,
    "subtotal_tax": 0.00,
    "total": 75.00,
    "total_tax": 0.00,
    "taxes": [
      
    ],
    "meta": [
      
    ]
  },
  {
    "id": 73,
    "name": "Італьяно",
    "sku": "340",
    "product_id": 1138,
    "variation_id": 0,
    "quantity": 1,
    "tax_class": "",
    "price": 38.00,
    "subtotal": 38.00,
    "subtotal_tax": 0.00,
    "total": 38.00,
    "total_tax": 0.00,
    "taxes": [
      
    ],
    "meta": [
      
    ]
  }
]

I need to write value from this JSON

for example name to variable.

How I can do this?

Community
  • 1
  • 1
Eugene
  • 231
  • 2
  • 13

1 Answers1

1

It depends on the order line item from where you want to write value from. Assuming int X and int Y to be less than equal to orders.count, orders.line_items.count respectively, You can get the values directly with orders[X].line_items[Y].Propertyname

A better idea would be to create classes representing the business objects and then translating property values into your objects and using it for your application purposes.

Sudhakar
  • 136
  • 7