简体   繁体   中英

How to query this json array

I want to be able to query my json file dynamically to get the following:

"CustomerID":{"value":"TCHCHIP0111"}

from this file:

[{
  "id": "62f687e7-eaa4-4999-b44a-5ccbc249bf34",
  "rowNumber": 1,
  "note": "",
  "AccountRef": {
    "value": "CP6000256"
  },
  "ApplyOverdueCharges": {
    "value": false
  },
  "AutoApplyPayments": {
    "value": false
  },
  "BillingAddressSameAsMain": {
    "value": true
  },
  "BillingContactSameAsMain": {
    "value": true
  },
  "CreatedDateTime": {
    "value": "2019-09-20T14:17:22.343+02:00"
  },
  "CurrencyID": {
    "value": "NAD"
  },
  "CurrencyRateType": {
    "value": "SPOT"
  },
  "CustomerClass": {
    "value": "PNP"
  },
  "CustomerID": {
    "value": "TCHCHIP0111"
  },
  "CustomerName": {
    "value": "Pick & Pay Retail C/kins Oshak"
  },
  "EnableCurrencyOverride": {
    "value": false
  },
  "EnableRateOverride": {
    "value": false
  },
  "EnableWriteOffs": {
    "value": false
  },
  "FOBPoint": {
    "value": "CP60"
  },
  "GLNNumber": {
    "value": "WN051000004279"
  },
  "LastModifiedDateTime": {
    "value": "2019-10-24T12:42:53.383+02:00"
  },
  "LeadTimedays": {},
  "LocationName": {
    "value": "Primary Location"
  },
  "MultiCurrencyStatements": {
    "value": false
  },
  "OrderPriority": {
    "value": 0
  },
  "ParentRecord": {
    "value": "TCHCHIPPNP"
  },
  "PriceClassID": {
    "value": "PNP"
  },
  "PrintInvoices": {
    "value": false
  },
  "PrintStatements": {
    "value": false
  },
  "ResidentialDelivery": {
    "value": false
  },
  "SaturdayDelivery": {
    "value": false
  },
  "SendInvoicesbyEmail": {
    "value": false
  },
  "SendStatementsbyEmail": {
    "value": false
  },
  "ShippingAddressSameAsMain": {
    "value": false
  },
  "ShippingBranch": {},
  "ShippingContactSameAsMain": {
    "value": false
  },
  "ShippingRule": {
    "value": "Cancel Remainder"
  },
  "ShippingTerms": {},
  "ShippingZoneID": {},
  "ShipVia": {},
  "StatementCycleID": {
    "value": "ENDOFMONTH"
  },
  "StatementType": {
    "value": "Open Item"
  },
  "Status": {
    "value": "Active"
  },
  "TaxRegistrationID": {},
  "TaxZone": {
    "value": "RECEIVER"
  },
  "Terms": {
    "value": "30D STATE"
  },
  "WarehouseID": {},
  "WriteOffLimit": {
    "value": 0.0000
  },
  "custom": {},
  "files": []
}, {
  "id": "445d97c3-411d-4587-ac86-8f84267c4324",
  "rowNumber": 2,
  "note": "",
  "AccountRef": {
    "value": "NC6000014"
  },
  "ApplyOverdueCharges": {
    "value": false
  },
  "AutoApplyPayments": {
    "value": false
  },
  "BillingAddressSameAsMain": {
    "value": true
  },
  "BillingContactSameAsMain": {
    "value": true
  },
  "CreatedDateTime": {
    "value": "2019-09-20T14:14:15.95+02:00"
  },
  "CurrencyID": {
    "value": "NAD"
  },
  "CurrencyRateType": {
    "value": "SPOT"
  },
  "CustomerClass": {
    "value": "PNP"
  },
  "CustomerID": {
    "value": "TCRDMIC0111"
  },
  "CustomerName": {
    "value": "Pick & Pay Dairy Maid Oshakati"
  },
  "EnableCurrencyOverride": {
    "value": false
  },
  "EnableRateOverride": {
    "value": false
  },
  "EnableWriteOffs": {
    "value": false
  },
  "FOBPoint": {
    "value": "IC60"
  },
  "GLNNumber": {
    "value": "WN051000004279"
  },
  "LastModifiedDateTime": {
    "value": "2019-10-24T10:56:49.463+02:00"
  },
  "LeadTimedays": {},
  "LocationName": {
    "value": "Primary Location"
  },
  "MultiCurrencyStatements": {
    "value": false
  },
  "OrderPriority": {
    "value": 0
  },
  "ParentRecord": {
    "value": "TCRDMICPNP"
  },
  "PriceClassID": {
    "value": "PNP"
  },
  "PrintInvoices": {
    "value": false
  },
  "PrintStatements": {
    "value": false
  },
  "ResidentialDelivery": {
    "value": false
  },
  "SaturdayDelivery": {
    "value": false
  },
  "SendInvoicesbyEmail": {
    "value": false
  },
  "SendStatementsbyEmail": {
    "value": false
  },
  "ShippingAddressSameAsMain": {
    "value": false
  },
  "ShippingBranch": {},
  "ShippingContactSameAsMain": {
    "value": false
  },
  "ShippingRule": {
    "value": "Cancel Remainder"
  },
  "ShippingTerms": {},
  "ShippingZoneID": {},
  "ShipVia": {},
  "StatementCycleID": {
    "value": "ENDOFMONTH"
  },
  "StatementType": {
    "value": "Open Item"
  },
  "Status": {
    "value": "Active"
  },
  "TaxRegistrationID": {},
  "TaxZone": {
    "value": "RECEIVER"
  },
  "Terms": {
    "value": "30D"
  },
  "WarehouseID": {},
  "WriteOffLimit": {
    "value": 0.0000
  },
  "custom": {},
  "files": []
}]

If you're using Newtonsoft.Json then you can use JsonConvert.DeserializeObject and dynamic to get the results as a JObject . Then you can iterate over the results:

    var results = JsonConvert.DeserializeObject<dynamic>(json);
    foreach (var item in results)
    {
        Console.WriteLine(item.CustomerID);
    }

Or, you can use LINQ to get only the CustomerIDs:

    var customerIds = ((IEnumerable<dynamic>)results).Select(r => r.CustomerID);
    foreach (var id in customerIds)
    {
        Console.WriteLine(id);
    }

Try it online

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM