Brauche Hilfe beim Parsen von JSON

Ich scheitere schon bei den ersten beiden Zeilen :wink:
Achso, habe Xojo 2017R3

Dim jsonArray() As Auto
jsonArray=Xojo.Data.ParseJSON(editfield1.text)

Fehler: Parameter “json” expects type Text, but this is type String.

Dann sollte es so weiter gehen, jede Bestellung hat eine id:
Dim value As Text
For Each d As Xojo.Core.Dictionary In jsonArray
value = d.Value(“id”)
Next

Versuch’s mal damit:

Dim jsonArray() As Auto
jsonArray = Xojo.Data.ParseJSON(EditField1.Text.ToText)

Ok, das klappt nun so, ich bekomme bei value alle Bestell-IDs, die vorhanden sind.

  Dim jsonArray() As Auto
  jsonArray=Xojo.Data.ParseJSON(editfield1.text.ToText)
  
  Dim value As integer
  For Each d As Xojo.Core.Dictionary In jsonArray
    value = d.Value("id")
      Next

Und an die nächste Ebene komme ich dann so? Das wars schon?

    Dim jsonArray() As Auto
      jsonArray=Xojo.Data.ParseJSON(editfield1.text.ToText)
      
      Dim value As integer
      For Each d As Xojo.Core.Dictionary In jsonArray
        value = d.Value("id")

        Dim billing As Xojo.Core.Dictionary = d.Value("billing")
        firstname=billing.Value("first_name")

 Dim shipping As Xojo.Core.Dictionary = d.Value("shipping")
        delivery_firstname=shipping.Value("first_name")

          Next

Kannst Du mal dein ganzes JSON hier reinstellen? Das erhöht die Chancen, dass jemand mal rumprobiert ;-). Die Werte in den Gänsefüsschen kannst Du ja anpassen, wenn das Vertrauliches drinstehen sollte.

hast du so gemeint?

[{“id”:14154,“parent_id”:0,“status”:“completed”,“currency”:“EUR”,“version”:“4.9.0”,“prices_include_tax”:true,“date_created”:“2021-01-18T15:19:11”,“date_modified”:“2021-01-18T15:24:33”,“discount_total”:“0.00”,“discount_tax”:“0.00”,“shipping_total”:“3.74”,“shipping_tax”:“0.26”,“cart_tax”:“0.94”,“total”:“18.40”,“total_tax”:“1.20”,“customer_id”:0,“order_key”:“wc_order_ZmtOp6aBGxLif”,“billing”:{“first_name”:“Markus”,“last_name”:“Mustermann”,“company”:"",“address_1”:“Musterstraße 16/7”,“address_2”:"",“city”:“Musterort”,“state”:"",“postcode”:“95030”,“country”:“DE”,“email”:"mustermann.m@web.de",“phone”:"",“title”:“0”},“shipping”:{“first_name”:“Markus”,“last_name”:“Mustermann”,“company”:"",“address_1”:“Musterstraße 16/7”,“address_2”:"",“city”:“Musterort”,“state”:"",“postcode”:“95030”,“country”:“DE”,“title”:“0”},“payment_method”:“paypal”,“payment_method_title”:“PayPal”,“transaction_id”:“8XP340024T105474A”,“customer_ip_address”:“77.119.130.41”,“customer_user_agent”:“Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Mobile/15E148 Safari/604.1”,“created_via”:“checkout”,“customer_note”:"",“date_completed”:“2021-01-18T15:24:33”,“date_paid”:“2021-01-18T15:19:52”,“cart_hash”:“fc6e2295347ebb793633df09566d74dd”,“number”:“14154”,“meta_data”:[{“id”:123428,“key”:"_us_in_content_ids",“value”:""},{“id”:123429,“key”:"_us_grid_filter_atts",“value”:""},{“id”:123462,“key”:"_billing_title",“value”:“0”},{“id”:123463,“key”:"_shipping_title",“value”:“0”},{“id”:123464,“key”:"_shipping_address_type",“value”:""},{“id”:123465,“key”:“is_vat_exempt”,“value”:“no”},{“id”:123466,“key”:"_additional_costs_include_tax",“value”:“yes”},{“id”:123467,“key”:"_shipping_dhl_address_type",“value”:“regular”},{“id”:123469,“key”:“Payment type”,“value”:“instant”},{“id”:123471,“key”:"_paypal_status",“value”:“completed”},{“id”:123472,“key”:“PayPal Transaction Fee”,“value”:“0.81”},{“id”:123482,“key”:"_date_shipped",“value”:“1610979873”}],“line_items”:[{“id”:730,“name”:“Himmlische Kraftkarten”,“product_id”:9116,“variation_id”:0,“quantity”:1,“tax_class”:“ermaessigter-steuersatz”,“subtotal”:“13.46”,“subtotal_tax”:“0.94”,“total”:“13.46”,“total_tax”:“0.94”,“taxes”:[{“id”:18,“total”:“0.942056”,“subtotal”:“0.942056”}],“meta_data”:[{“id”:7415,“key”:"_unit",“value”:“St\u00fcck”,“display_key”:"_unit",“display_value”:“St\u00fcck”},{“id”:7416,“key”:"_unit_base",“value”:"",“display_key”:"_unit_base",“display_value”:""},{“id”:7417,“key”:"_unit_product",“value”:"",“display_key”:"_unit_product",“display_value”:""},{“id”:7418,“key”:"_item_desc",“value”:"",“display_key”:"_item_desc",“display_value”:""},{“id”:7419,“key”:"_delivery_time",“value”:“Lieferzeit: 2-5 Tage”,“display_key”:"_delivery_time",“display_value”:“Lieferzeit: 2-5 Tage”},{“id”:7420,“key”:"_min_age",“value”:"",“display_key”:"_min_age",“display_value”:""},{“id”:7436,“key”:"_reduced_stock",“value”:“1”,“display_key”:"_reduced_stock",“display_value”:“1”}],“sku”:“3301”,“price”:13.457944,“parent_name”:null}],“tax_lines”:[{“id”:732,“rate_code”:“AT-MWST.-2”,“rate_id”:18,“label”:“MwSt.”,“compound”:false,“tax_total”:“0.94”,“shipping_tax_total”:“0.26”,“rate_percent”:7,“meta_data”:[]}],“shipping_lines”:[{“id”:731,“method_title”:“Nach Gesamtgewicht”,“method_id”:“flexible_shipping”,“instance_id”:“11”,“total”:“3.74”,“total_tax”:“0.26”,“taxes”:[{“id”:18,“total”:“0.261682”,“subtotal”:""}],“meta_data”:[{“id”:7426,“key”:"_default",“value”:“yes”,“display_key”:"_default",“display_value”:“yes”},{“id”:7427,“key”:"_fs_method",“value”:{“woocommerce_method_instance_id”:“11”,“id”:“1”,“id_for_shipping”:“flexible_shipping_11_1”,“method_title”:“Nach Gesamtgewicht”,“method_description”:"",“method_free_shipping”:"",“method_free_shipping_label”:"",“method_calculation_method”:“sum”,“method_visibility”:“no”,“method_default”:“yes”,“method_enabled”:“yes”,“method_integration”:"",“method_rules”:[{“conditions”:[{“condition_id”:“weight”,“min”:“0”,“max”:“440”}],“cost_per_order”:“4.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“441”,“max”:“880”}],“cost_per_order”:“8.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“881”,“max”:“1880”}],“cost_per_order”:“12.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“1881”,“max”:“4500”}],“cost_per_order”:“26.000”,“additional_costs”:[],“special_action”:""}],“method_free_shipping_cart_notice”:“no”,“method_debug_mode”:“no”},“display_key”:"_fs_method",“display_value”:{“woocommerce_method_instance_id”:“11”,“id”:“1”,“id_for_shipping”:“flexible_shipping_11_1”,“method_title”:“Nach Gesamtgewicht”,“method_description”:"",“method_free_shipping”:"",“method_free_shipping_label”:"",“method_calculation_method”:“sum”,“method_visibility”:“no”,“method_default”:“yes”,“method_enabled”:“yes”,“method_integration”:"",“method_rules”:[{“conditions”:[{“condition_id”:“weight”,“min”:“0”,“max”:“440”}],“cost_per_order”:“4.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“441”,“max”:“880”}],“cost_per_order”:“8.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“881”,“max”:“1880”}],“cost_per_order”:“12.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“1881”,“max”:“4500”}],“cost_per_order”:“26.000”,“additional_costs”:[],“special_action”:""}],“method_free_shipping_cart_notice”:“no”,“method_debug_mode”:“no”}},{“id”:7428,“key”:“description”,“value”:"",“display_key”:“description”,“display_value”:""},{“id”:7429,“key”:“Positionen”,“value”:“Himmlische Kraftkarten × 1”,“display_key”:“Positionen”,“display_value”:“Himmlische Kraftkarten × 1”}]}],“fee_lines”:[],“coupon_lines”:[],“refunds”:[],“date_created_gmt”:“2021-01-18T14:19:11”,“date_modified_gmt”:“2021-01-18T14:24:33”,“date_completed_gmt”:“2021-01-18T14:24:33”,“date_paid_gmt”:“2021-01-18T14:19:52”,“shipments”:[{“id”:117,“date_created”:“2021-01-18T15:19:52”,“date_created_gmt”:“2021-01-18T14:19:52”,“date_sent”:“2021-01-18T15:24:33”,“date_sent_gmt”:“2021-01-18T14:24:33”,“est_delivery_date”:null,“est_delivery_date_gmt”:null,“total”:“14.40”,“weight”:“220”,“status”:“shipped”,“tracking_id”:“A001FFD06B000000068B”,“tracking_url”:"",“shipping_provider”:“deutsche_post”,“dimensions”:{“length”:“0”,“width”:“0”,“height”:“0”},“address”:{“first_name”:“Markus”,“last_name”:“Mustermann”,“company”:"",“address_1”:“Musterstraße 16/7”,“address_2”:"",“city”:“Musterort”,“state”:"",“postcode”:“95030”,“country”:“DE”,“email”:"mustermann.m@web.de",“phone”:""},“items”:[{“id”:211,“name”:“Himmlische Kraftkarten”,“order_item_id”:730,“product_id”:9116,“quantity”:1}]}],“currency_symbol”:"\u20ac",“parcel_delivery_opted_in”:"",“direct_debit”:{“holder”:"",“iban”:"",“bic”:"",“mandate_id”:""},"_links":{“self”:[{“href”:“https://meinwebshop.de.de/wp-json/wc/v3/orders/14154"}],“collection”:[{“href”:"https://meinwebshop.de/wp-json/wc/v3/orders”}]}}]

Fast, irgendwas ist “abgeschnitten”:

Es gibt online tools, die dein JSON checken: https://jsonformatter.curiousconcept.com/

Es muss halt valider JSON code sein, am besten mit der Code Funktion im Editor:

Bildschirmfoto 2021-01-20 um 10.17.45

hier reinstellen.

Hallo Stefan, ich hatte Beispielprojekte online gestellt, für das Schreiben und Lesen von Woo Daten. Eines war für einen Vortrag an der MBS Xojo Con 2018.

Vielleicht hilft Dir das weiter?

1 Like

Der Code ist komplett und kann auch problemlos in Xojo verarbeitet werden.

Als Code wird es eine einzige Zeile:

[{“id”:14154,“parent_id”:0,“status”:“completed”,“currency”:“EUR”,“version”:“4.9.0”,“prices_include_tax”:true,“date_created”:“2021-01-18T15:19:11”,“date_modified”:“2021-01-18T15:24:33”,“discount_total”:“0.00”,“discount_tax”:“0.00”,“shipping_total”:“3.74”,“shipping_tax”:“0.26”,“cart_tax”:“0.94”,“total”:“18.40”,“total_tax”:“1.20”,“customer_id”:0,“order_key”:“wc_order_ZmtOp6aBGxLif”,“billing”:{“first_name”:“Markus”,“last_name”:“Mustermann”,“company”:"",“address_1”:“Musterstraße 16/7”,“address_2”:"",“city”:“Musterort”,“state”:"",“postcode”:“95030”,“country”:“DE”,“email”:"mustermann.m@web.de",“phone”:"",“title”:“0”},“shipping”:{“first_name”:“Markus”,“last_name”:“Mustermann”,“company”:"",“address_1”:“Musterstraße 16/7”,“address_2”:"",“city”:“Musterort”,“state”:"",“postcode”:“95030”,“country”:“DE”,“title”:“0”},“payment_method”:“paypal”,“payment_method_title”:“PayPal”,“transaction_id”:“8XP340024T105474A”,“customer_ip_address”:“77.119.130.41”,“customer_user_agent”:“Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Mobile/15E148 Safari/604.1”,“created_via”:“checkout”,“customer_note”:"",“date_completed”:“2021-01-18T15:24:33”,“date_paid”:“2021-01-18T15:19:52”,“cart_hash”:“fc6e2295347ebb793633df09566d74dd”,“number”:“14154”,“meta_data”:[{“id”:123428,“key”:"_us_in_content_ids",“value”:""},{“id”:123429,“key”:"_us_grid_filter_atts",“value”:""},{“id”:123462,“key”:"_billing_title",“value”:“0”},{“id”:123463,“key”:"_shipping_title",“value”:“0”},{“id”:123464,“key”:"_shipping_address_type",“value”:""},{“id”:123465,“key”:“is_vat_exempt”,“value”:“no”},{“id”:123466,“key”:"_additional_costs_include_tax",“value”:“yes”},{“id”:123467,“key”:"_shipping_dhl_address_type",“value”:“regular”},{“id”:123469,“key”:“Payment type”,“value”:“instant”},{“id”:123471,“key”:"_paypal_status",“value”:“completed”},{“id”:123472,“key”:“PayPal Transaction Fee”,“value”:“0.81”},{“id”:123482,“key”:"_date_shipped",“value”:“1610979873”}],“line_items”:[{“id”:730,“name”:“Himmlische Kraftkarten”,“product_id”:9116,“variation_id”:0,“quantity”:1,“tax_class”:“ermaessigter-steuersatz”,“subtotal”:“13.46”,“subtotal_tax”:“0.94”,“total”:“13.46”,“total_tax”:“0.94”,“taxes”:[{“id”:18,“total”:“0.942056”,“subtotal”:“0.942056”}],“meta_data”:[{“id”:7415,“key”:"_unit",“value”:“St\u00fcck”,“display_key”:"_unit",“display_value”:“St\u00fcck”},{“id”:7416,“key”:"_unit_base",“value”:"",“display_key”:"_unit_base",“display_value”:""},{“id”:7417,“key”:"_unit_product",“value”:"",“display_key”:"_unit_product",“display_value”:""},{“id”:7418,“key”:"_item_desc",“value”:"",“display_key”:"_item_desc",“display_value”:""},{“id”:7419,“key”:"_delivery_time",“value”:“Lieferzeit: 2-5 Tage”,“display_key”:"_delivery_time",“display_value”:“Lieferzeit: 2-5 Tage”},{“id”:7420,“key”:"_min_age",“value”:"",“display_key”:"_min_age",“display_value”:""},{“id”:7436,“key”:"_reduced_stock",“value”:“1”,“display_key”:"_reduced_stock",“display_value”:“1”}],“sku”:“3301”,“price”:13.457944,“parent_name”:null}],“tax_lines”:[{“id”:732,“rate_code”:“AT-MWST.-2”,“rate_id”:18,“label”:“MwSt.”,“compound”:false,“tax_total”:“0.94”,“shipping_tax_total”:“0.26”,“rate_percent”:7,“meta_data”:[]}],“shipping_lines”:[{“id”:731,“method_title”:“Nach Gesamtgewicht”,“method_id”:“flexible_shipping”,“instance_id”:“11”,“total”:“3.74”,“total_tax”:“0.26”,“taxes”:[{“id”:18,“total”:“0.261682”,“subtotal”:""}],“meta_data”:[{“id”:7426,“key”:"_default",“value”:“yes”,“display_key”:"_default",“display_value”:“yes”},{“id”:7427,“key”:"_fs_method",“value”:{“woocommerce_method_instance_id”:“11”,“id”:“1”,“id_for_shipping”:“flexible_shipping_11_1”,“method_title”:“Nach Gesamtgewicht”,“method_description”:"",“method_free_shipping”:"",“method_free_shipping_label”:"",“method_calculation_method”:“sum”,“method_visibility”:“no”,“method_default”:“yes”,“method_enabled”:“yes”,“method_integration”:"",“method_rules”:[{“conditions”:[{“condition_id”:“weight”,“min”:“0”,“max”:“440”}],“cost_per_order”:“4.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“441”,“max”:“880”}],“cost_per_order”:“8.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“881”,“max”:“1880”}],“cost_per_order”:“12.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“1881”,“max”:“4500”}],“cost_per_order”:“26.000”,“additional_costs”:[],“special_action”:""}],“method_free_shipping_cart_notice”:“no”,“method_debug_mode”:“no”},“display_key”:"_fs_method",“display_value”:{“woocommerce_method_instance_id”:“11”,“id”:“1”,“id_for_shipping”:“flexible_shipping_11_1”,“method_title”:“Nach Gesamtgewicht”,“method_description”:"",“method_free_shipping”:"",“method_free_shipping_label”:"",“method_calculation_method”:“sum”,“method_visibility”:“no”,“method_default”:“yes”,“method_enabled”:“yes”,“method_integration”:"",“method_rules”:[{“conditions”:[{“condition_id”:“weight”,“min”:“0”,“max”:“440”}],“cost_per_order”:“4.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“441”,“max”:“880”}],“cost_per_order”:“8.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“881”,“max”:“1880”}],“cost_per_order”:“12.000”,“additional_costs”:[],“special_action”:""},{“conditions”:[{“condition_id”:“weight”,“min”:“1881”,“max”:“4500”}],“cost_per_order”:“26.000”,“additional_costs”:[],“special_action”:""}],“method_free_shipping_cart_notice”:“no”,“method_debug_mode”:“no”}},{“id”:7428,“key”:“description”,“value”:"",“display_key”:“description”,“display_value”:""},{“id”:7429,“key”:“Positionen”,“value”:“Himmlische Kraftkarten × 1”,“display_key”:“Positionen”,“display_value”:“Himmlische Kraftkarten × 1”}]}],“fee_lines”:[],“coupon_lines”:[],“refunds”:[],“date_created_gmt”:“2021-01-18T14:19:11”,“date_modified_gmt”:“2021-01-18T14:24:33”,“date_completed_gmt”:“2021-01-18T14:24:33”,“date_paid_gmt”:“2021-01-18T14:19:52”,“shipments”:[{“id”:117,“date_created”:“2021-01-18T15:19:52”,“date_created_gmt”:“2021-01-18T14:19:52”,“date_sent”:“2021-01-18T15:24:33”,“date_sent_gmt”:“2021-01-18T14:24:33”,“est_delivery_date”:null,“est_delivery_date_gmt”:null,“total”:“14.40”,“weight”:“220”,“status”:“shipped”,“tracking_id”:“A001FFD06B000000068B”,“tracking_url”:"",“shipping_provider”:“deutsche_post”,“dimensions”:{“length”:“0”,“width”:“0”,“height”:“0”},“address”:{“first_name”:“Markus”,“last_name”:“Mustermann”,“company”:"",“address_1”:“Musterstraße 16/7”,“address_2”:"",“city”:“Musterort”,“state”:"",“postcode”:“95030”,“country”:“DE”,“email”:"mustermann.m@web.de",“phone”:""},“items”:[{“id”:211,“name”:“Himmlische Kraftkarten”,“order_item_id”:730,“product_id”:9116,“quantity”:1}]}],“currency_symbol”:"\u20ac",“parcel_delivery_opted_in”:"",“direct_debit”:{“holder”:"",“iban”:"",“bic”:"",“mandate_id”:""},"_links":{“self”:[{“href”:“https://meinwebshop.de.de/wp-json/wc/v3/orders/14154"}],“collection”:[{“href”:"https://meinwebshop.de/wp-json/wc/v3/orders”}]}}]

Danke Oliver,

das hätte ich mal vorher finden müssen, aber es hilft mir auch jetzt noch.

1 Like

Ah, habe den Fehler gefunden (war vorhin unterwegs), das Forum verzwirbelt die Gänsefüsschen. Habe die durch “richtige” ersetzt jetzt klappt es und die Fehler unten sind weg:

Das Programm hier ist übrigens sehr hilfreich um mit JSONs zu “spielen”: http://www.smartjsoneditor.com/

Ok, verstehe.
Ja abschließend kann ich sagen, dass sich Json aus meiner Sicht leichter parsen lässt als XML.
Und WooCommerce bzw. WP mit der Rest API kann quasi alles ausspucken, was man brauchen könnte.
Kann ich empfehlen!

Ja JSON ist sehr “cool”. Ist nur etwas problematisch eine eierlegende Wollmilchsau zu programmieren, also etwas, das quasi dynamisch alle JSONs interpretieren könnte, man muss die Struktur des jeweiligen JSONs halt kennen. Ist auch schön performant. Und wenn man massenweise damit rummachen muss, oder die Plugins eh schon hat, dann sind die JSON Klassen von MBS eine große Hilfe.

1 Like

sodele, quick and (very) dirty … :wink:

Und hier der Code für ein paar Felder, ich denke das gibt Dir die Idee hinter dem JSON Konzept, und Du kannst es verfeinern. Wichtig bei JSON ist es immer mit TRY / CATCH zu arbeiten, weil das JSON was Du heute bekommst, sich morgen leider in der Struktur geändert haben könnte usw. Passiert bei großen Anbietern eher selten, bei kleinen “Nischen-APIs” und/oder Startup ist es leider oft die Regel …

// myJSON ist als String-Property definiert und hat Dein JSON als value

Var content() As Variant
content = ParseJSON( myJSON )

// Root-Ebenen (2 Beispiele) 
var waehrung as string = Dictionary( content(0)).Value("currency") 
var total as currency = Dictionary( content(0)).Value("total") 
// usw.

// Doof wird es jetzt bei den Shipements z.B.
// Das ist in sich ein Array

// Der folgende Code würde also voll auf die Bretter gehen
// var shipments as string = Dictionary( content(0)).Value("shipments") 
// Also müssen wir das jetzt auch erst einmal in einen Array übertragen:

var shipments() as variant = Dictionary( content(0)).Value("shipments") 

// jetzt hast Du die Shipments und kannst wieder auf alles in deren "Root-Eben wie oben zugreifen

var gewicht as string = Dictionary( shipments(0)).Value("weight")

// und so weiter und so fort, ich denke Du bekommst jetzt die Idee und Logik dahinter

break`

Wenn nun in shipments wieder ein Array auftauchen würde, dann müsstest Du den wieder in ein Array zwischenspeichern usw. Deswegen sind kostenlose Tools wie SMART Json Editor hilfreich, da sie einem die Struktur anzeigen. Und auch wenn ich ein großer Fan von Cloud-Lösungen bin, so beinhalten JSONs ja oft sensible Daten, da ist mir dann ein Offline JSON Editor doch lieber, als meine (Kunden-)Daten irgendwo in eine Cloud zu funken …

Ich danke, dir, ich habe es verstanden… sollte ich irgendwo hängen bleiben, melde ich mich wieder.

Liebe Grüße

Stefan

1 Like

Gerne, LG Jeannot

Ich habs wohl nicht verstanden :upside_down_face:

Meine Code schaut nun so aus:

  Dim jsonArray() As Auto
  jsonArray=Xojo.Data.ParseJSON(editfield1.text.ToText)
        For Each d As Xojo.Core.Dictionary In jsonArray
          contact_id=str(zahl_d) // 0 wenn als Gast bestellt
         zahlung=d.Value("payment_method_title")
        customer_note=d.Value("customer_note")
        usw.

      Dim billing As Xojo.Core.Dictionary = d.Value("billing")
         firstname=billing.Value("first_name")
           lastname=billing.Value("last_name")
             company=billing.Value("company")
             usw.

     // jetzt soll das Array line_items ausgelesen werden
   // für jedes Item in line_items
     // wie passt da jetzt dein Beispiel rein? Ich bekomme es nicht gebacken

    Next

einfach als Array auslesen. Auch wenn es unter “line_items” in Deinem Beispiel nur ein Item(0) gibt, könnten eben mehrere drin stehen. Wahrscheinlich nicht, aber aus JSON Sicht schon, sprich das JSON hat eben gerade da ein Array, und muss dann auch so behandelt werden.

  Dim jsonArray() As Auto
  jsonArray=Xojo.Data.ParseJSON(myJSON)
  
  For Each d As Xojo.Core.Dictionary In jsonArray
    'contact_id=str(zahl_d) // 0 wenn als Gast bestellt
    var zahlung as String = d.Value("payment_method_title")
    Var customer_note as String =d.Value("customer_note")
    // usw.
    
    Dim billing As Xojo.Core.Dictionary = d.Value("billing")
    Var firstname as string = billing.Value("first_name")
    Var lastname as string = billing.Value("last_name")
    Var company as string = billing.Value("company")
    
    // jetzt soll das Array line_items ausgelesen werden
    // für jedes Item in line_items
    // wie passt da jetzt dein Beispiel rein? Ich bekomme es nicht gebacken
    Var lineItems() As auto = d.Value("line_items")
    for each item as Xojo.Core.Dictionary in lineItems
      Var produktname as string = item.value("name")
      var steuerklasse as string = item.value("tax_class")
      break
    Next
  next

Jetzt läuft es, nochmal danke!

1 Like