2017-08-24 20 views
0

我有第三方Web服務,我使用VB.Net檢索數據。 Web服務已經經歷了3個階段,SOAP作爲XML,然後REST作爲XML現在最終以REST作爲Json。以及將認證方法更改爲API密鑰和承載。創建類/模型,以便Json返回可以投入使用DeserializeObject

因此,我們被迫再次重新編寫所有從這些Web服務發佈並獲取數據的應用程序,更好的是,它們將很快退休所有其他方法。 所以我匆忙試圖讓我們所有的錄音完成。

一部分IM具有的把JSON成從IM能夠在代碼導航(在XML ID只是我們爲XML對象,並經過節點)

香港專業教育學院讀我要創建一個麻煩對象模型,該JSON結構以反序列化爲相匹配,但有麻煩的是模型IM .. (我不能使用Newtonsoft Json.NET要麼)

下面是將JSON返回一個命令,但它的一個陣列1 -1000每退貨訂單..

我會繼續擺弄自己,但希望一個o如果你能簡單地解釋一下我必須建立的班級來完成工作! (對不起IVE除去了大部分數據只是假定「」是一個字符串(這是大多數零點)和##是數字)

{ 
    "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

複製的Json到剪貼板,然後**編輯菜單** - > **選擇性粘貼** - > **粘貼JSON作爲類**。請閱讀[問]並參加[導覽] – Plutonix

+0

「將Json複製到剪貼板,然後編輯菜單 - >選擇性粘貼 - >粘貼Json作爲課程」 在哪個應用程序中? 乾杯:) –

回答

0

羞恥你不能使用JSON.net,它使這種事情要容易得多。如果一個完整的模型太麻煩了,你可以嘗試使用字典來簡化它。

JSON本質上是一組鍵/值對,因此,如果您爲對象設置了嵌套權限,則通常可以將所有內容保存在一些字典中。

在你的情況下,嵌套在「付款」和「orderItems」應該做的伎倆。希望這有助於你開始。

+0

使用字典只是錯誤了,我認爲json要麼太複雜,要麼包含關鍵詞Date? 我確信我增加了串行最大長度,以防萬一它是太長.. 昏暗JSS作爲新JavaScriptSerializer() jss.MaxJsonLength = 86753090點 –

+0

它不是太長,但它不是一組簡單的鍵 - 值對。例如'payments'和'orderitems'就是Types。請閱讀[問]並參加[旅遊] @GlenRichmond – Plutonix

+0

我會嘗試嵌套建議謝謝.. –

0

我個人已經爲XDocument模塊創建了一個JSON,它接受一個JSON文本,然後將其轉換爲一個XDocument對象。這將允許您輕鬆地查詢所需的節點(可能代表屬性)。

這裏的github上:https://github.com/dday9/.NET-JSON-Transformer

相關問題