CSharp · Console
using System;
using Oss.DCodec; // https://www.nuget.org/packages/Oss.DCodec
public class Program
{
public static void Main()
{
string json = @"{
'billingAddress': {
'zip': '64001340',
'state': 'PI',
'number': '3443',
'status': 'ACTIVE',
'firstName': 'Fulano',
'telephone': {
'type': 'billing',
'number': '88112244'
},
'neighbourhood': 'Centro'
},
'clientId': 'cliente3',
'documents': [
{
'type': 'cpf',
'number': '12345678901'
}
],
'fulfillments': {
'F1': {
'id': 'F1',
'orderId': '4017116',
'channelId': 'channel2',
'clientId': 'cliente3',
'locationId': '708',
'shipment': {
'method': 'Economica',
'carrierName': 'Transportadora'
},
'status': 'CANCELED',
'type': 'SHIPMENT',
'enablePrePicking': false,
'items': {
'03.64.0005_11_10': {
'sku': '03.64.0005_11_10',
'quantity': 0,
'stockType': 'PHYSICAL',
'orderedQuantity': 1,
'returnedQuantity': 0,
'canceledQuantity': 1,
'itemType': 'OTHER',
'presale': false,
'enablePicking': true
},
'18.06.0220_48_2': {
'sku': '18.06.0220_48_2',
'quantity': 0,
'stockType': 'PHYSICAL',
'orderedQuantity': 1,
'returnedQuantity': 0,
'canceledQuantity': 1,
'itemType': 'OTHER',
'presale': false,
'enablePicking': true
}
}
},
'F2': {
'id': 'F2',
'orderId': '4017116',
'channelId': 'channel2',
'clientId': 'cliente3',
'locationId': '003',
'operator': {
'id': '5188',
'name': 'Loja da Vila'
},
'ownership': 'oms',
'shipment': {
'method': 'Economica',
'carrierName': 'Transportadora'
},
'status': 'SHIPPING_READY',
'type': 'SHIPMENT',
'enablePrePicking': true,
'items': {
'18.04.1465_01_3': {
'sku': '18.04.1465_01_3',
'quantity': 1,
'stockType': 'PHYSICAL',
'orderedQuantity': 1,
'returnedQuantity': 0,
'canceledQuantity': 0,
'itemType': 'OTHER',
'presale': false,
'enablePicking': true
},
'18.16.0630_13_10': {
'sku': '18.16.0630_13_10',
'quantity': 1,
'stockType': 'PHYSICAL',
'orderedQuantity': 1,
'returnedQuantity': 0,
'canceledQuantity': 0,
'itemType': 'OTHER',
'presale': false,
'enablePicking': true
}
}
}
},
'createdAt': '2019-06-08T21:41:12.000Z',
'updatedAt': '2019-06-08T21:41:12.000Z'
}";
var myCodec = new Oss.DCodec.JsonCodec();
dynamic myData = myCodec.Decode(json); // example of dynamic object
if (myData.Fulfillments.ContainsKey("F1"))
{
foreach (var item in myData.Fulfillments.F1.Items as Oss.DCodec.DValue)
{
Item pocoItem = item.ToObject<Item>(); // convert dynamic object to POCO object
Console.WriteLine(pocoItem.sku +":" + pocoItem.quantity);
}
}
}
public class Item // https://stackoverflow.com/questions/3392580/explanation-of-poco
{
public string sku { get; set; }
public int quantity { get; set; }
public string stockType { get; set; }
public int orderedQuantity { get; set; }
public int returnedQuantity { get; set; }
public int canceledQuantity { get; set; }
public string itemType { get; set; }
public bool presale { get; set; }
public bool enablePicking { get; set; }
}
}