Hallo,
ich habe zum ersten mal mit Json zu tun und komme hier ziemlich in's Schleudern.
Ich habe ein komplexes Json, das mehrere Unterebenen hat, die ziemlich verschachtelt sind.
Ich kann bislang nur die obererste Ebene auslesen. Das mache ich mit folgendem Code, den ich online gefunden habe:
Allerdings begreife ich nicht, wie ich den auf die nächste höheren Ebenen springen kann.
Mein Json sieht so aus:
{"Timestamp":"2017-03-07T15:45:50.000Z","Ack":"Success","Version":"967","Build":"E967_INTL_APISELLING_17965958_R1","SaleRecord":[{"SellingManagerSoldTransaction":[{"TransactionID":1361189289020,"SaleRecordID":3185,"ItemID":"302210133391","QuantitySold":1,"ItemTitle":"Testartikel ","ListingType":"StoresFixedPrice","Relisted":false,"SecondChanceOfferSent":false,"CustomLabel":"ZY006","SoldOn":"eBay","ListedOn":["eBay"],"CharityListing":false,"OrderLineItemID":"3022-136"}],"ShippingAddress":{"Name":"Frau XY","PostalCode":"12345"},"ShippingDetails":{"ShippingType":"Flat"},"TotalAmount":{"value":233.95,"currencyID":"EUR"},"TotalQuantity":1,"ActualShippingCost":{"value":0,"currencyID":"EUR"},"OrderStatus":{"CheckoutStatus":"CheckoutComplete","PaidStatus":"Paid","ShippedStatus":"Unshipped","PaymentMethodUsed":"PayPal","FeedbackSent":false,"TotalEmailsSent":1,"PaidTime":"2017-03-07T14:28:48.000Z"},"SalePrice":{"value":233.95,"currencyID":"EUR"},"DaysSinceSale":0,"BuyerID":"katjuscha-blau","BuyerEmail":"xxx@web.de","SaleRecordID":3185,"CreationTime":"2017-03-07T14:27:15.000Z"}],"PaginationResult":{"TotalNumberOfPages":1,"TotalNumberOfEntries":13}}
ich habe zum ersten mal mit Json zu tun und komme hier ziemlich in's Schleudern.
Ich habe ein komplexes Json, das mehrere Unterebenen hat, die ziemlich verschachtelt sind.
Ich kann bislang nur die obererste Ebene auslesen. Das mache ich mit folgendem Code, den ich online gefunden habe:
VB.NET-Quellcode
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim json As String = File.ReadAllText("json.txt")
- ' Dim json As String = "{"id": "100001363520746", "name": "Jenni Hapunkt", "first_name": "Jenni", "last_name": "Hapunkt", "gender": "female","locale": "de_DE" }"
- ' javascript serialisierer
- Dim jsonSerializer As New System.Web.Script.Serialization.JavaScriptSerializer
- ' generisch zu json dictionary konvertieren
- Dim dict1 As Dictionary(Of String, Object) = jsonSerializer.Deserialize(Of Dictionary(Of String, Object))(json)
- ' oder standardmässig über deserializeobject + casten
- ' Dim o As Object = jsonSerializer.DeserializeObject(json)
- ' Dim dict2 As Dictionary(Of String, Object) = DirectCast(o, Dictionary(Of String, Object))
- ' ansprechen kann man es jetzt einfach
- MessageBox.Show(CStr(dict1("Timestamp"))) ' die objekte im dict müssen noch richtig gecastet werden
- End Sub
Allerdings begreife ich nicht, wie ich den auf die nächste höheren Ebenen springen kann.
Mein Json sieht so aus:
{"Timestamp":"2017-03-07T15:45:50.000Z","Ack":"Success","Version":"967","Build":"E967_INTL_APISELLING_17965958_R1","SaleRecord":[{"SellingManagerSoldTransaction":[{"TransactionID":1361189289020,"SaleRecordID":3185,"ItemID":"302210133391","QuantitySold":1,"ItemTitle":"Testartikel ","ListingType":"StoresFixedPrice","Relisted":false,"SecondChanceOfferSent":false,"CustomLabel":"ZY006","SoldOn":"eBay","ListedOn":["eBay"],"CharityListing":false,"OrderLineItemID":"3022-136"}],"ShippingAddress":{"Name":"Frau XY","PostalCode":"12345"},"ShippingDetails":{"ShippingType":"Flat"},"TotalAmount":{"value":233.95,"currencyID":"EUR"},"TotalQuantity":1,"ActualShippingCost":{"value":0,"currencyID":"EUR"},"OrderStatus":{"CheckoutStatus":"CheckoutComplete","PaidStatus":"Paid","ShippedStatus":"Unshipped","PaymentMethodUsed":"PayPal","FeedbackSent":false,"TotalEmailsSent":1,"PaidTime":"2017-03-07T14:28:48.000Z"},"SalePrice":{"value":233.95,"currencyID":"EUR"},"DaysSinceSale":0,"BuyerID":"katjuscha-blau","BuyerEmail":"xxx@web.de","SaleRecordID":3185,"CreationTime":"2017-03-07T14:27:15.000Z"}],"PaginationResult":{"TotalNumberOfPages":1,"TotalNumberOfEntries":13}}