我有第三方网络服务,我使用VB.Net检索数据。 Web服务已经经历了3个阶段,SOAP作为XML,然后REST作为XML现在最终REST作为Json。以及将身份验证方法更改为API密钥和承载。
因此我们再次被迫重新编写所有发布并从这些Web服务获取数据的应用程序,更好的是他们将很快退休所有其他方法。 所以我匆匆试图完成所有录音。
我遇到麻烦的一部分就是将json放入一个能够在代码中导航的地方(在xml id中只是我们作为xml对象并通过节点)
我已经读过我必须创建一个与Json结构匹配的对象模型,以便反序列化,但是我在制作该模型时遇到了麻烦。 (我也不能使用Newtonsoft Json.NET)
下面是一个订单的Json返回,但是每个返回的数组为1 - 1000个订单..
我将继续摆弄自己,但希望你们中的一个人能够简单地解释我必须建造的课程以完成工作! (对不起,我删除了大多数数据,只是假设“”是一个字符串(与大多数空值一样),##是数字)
{
"outgoingOrders": {
"order": [
{
"orderType": "",
"orderSource": "",
"espOrderNo": ###,
"invoiceNumber": "",
"externalReference": "",
"date": "2017-08-23T23:51:02+0100",
"customerCompany": null,
"customerName": "",
"customerAddress1": "",
"customerAddress2": null,
"customerAddress3": null,
"customerCity": "",
"customerCounty": "",
"customerPostcode": "",
"customerCountry": "",
"customerEmail": "",
"customerTelephone": "",
"customerFax": null,
"customerReference": null,
"customerNotes": null,
"deliveryCompany": null,
"deliveryName": null,
"deliveryAddress1": null,
"deliveryAddress2": null,
"deliveryAddress3": null,
"deliveryCity": null,
"deliveryCounty": null,
"deliveryPostcode": null,
"deliveryCountry": null,
"deliveryTelephone": null,
"shippingMethod": "",
"shippingCost": ##.##,
"insurance": 0.0,
"discount": 0.0,
"voucherCode": null,
"orderTotal": ##.##,
"paymentComplete": true,
"payments": {
"payment": [
{
"paymentMethod": "",
"paymentReference": "",
"paymentNotes": null,
"paymentCCDetails": null,
"paymentGateway": null,
"payPalEmail": "",
"payPalTransactionID": "",
"payPalProtectionEligibility": true,
"amount": ##.##,
"paymentDate": "2017-08-23T00:00:00+0100",
"paymentId": #####,
"postedBatchId": 0
}
]
},
"currencyCode": "",
"sellerUsername": "",
"sellerId": #,
"courierProfileName": "",
"buyerId": "",
"orderItems": {
"item": [
{
"webProductID": "",
"stockNumber": "",
"itemNumber": "",
"productTitle": "",
"quantity": #,
"unitCost": #,
"taxRate": #,
"taxCode": null,
"unitCostIncludesTax": "",
"weight": 31000.0,
"productFolderName": "#",
"creditReason": null,
"customMessage1": null,
"customMessage2": null,
"customMessage3": null,
"locationId": ####,
"supplierId": ##,
"kitType": "",
"kitMaster": "",
"picked": false,
"backOrder": false
}
]
},
"storeId": null,
"shipToStore": null,
"orderCredits": null,
"orderStatus": "",
"flag1": "",
"flag2": null,
"courierName": "",
"courierService": " ",
"courierServiceCode": "",
"fulfilmentType": "",
"webOrderID": #####,
"shippingDate": "2017-08-24T11:16:51+0100",
"invoiceDate": "2017-08-23",
"tradeSale": false,
"courierTracking": ""
}
]
},"pageContext":{"timestamp":"2017-08-24T14:02:23+0100","hasMoreEntries":false,"pageSize":1}}
答案 0 :(得分:0)
羞耻你不能使用JSON.net,它使这种事情变得如此简单。如果完整模型太成问题,您可以尝试使用字典来简化它。
JSON本质上是一组键/值对,所以只要你为对象获得正确的嵌套,你就可以将整个事物放在几个字典中。
在您的情况下,嵌套在“payment”和“orderItems”应该可以解决问题。希望这有助于您入门。
答案 1 :(得分:0)
我个人已经创建了一个JSON到XDocument模块,它接收一个JSON文字,然后将其转换为XDocument对象。这将允许您轻松查询所需的节点(可能代表属性)。