I know there are already a lot of posts about this, but I couldn't find one to fix my problem. Btw I already checked if the encoding is wrong. Also, sometimes the Exception throws and sometimes not. If it doesn't throw, "amd" is "Nothing" in the debugger.
Here is my code to deserialize the json-File
If OpenfilePath IsNot Nothing Then Dim myStreamReader As New StreamReader(OpenfilePath) Dim amd = JsonConvert.DeserializeObject(Of RootObject())(myStreamReader.ToString) 'That's where the Exception appears End If
Here is the Root Object Class (the class was automatically created by VS, i just added the JsonProperties and changed the name of the Public Properties):
Public Class RootObject Public Class Rootobject <JsonProperty(PropertyName:="Artikelstammdaten")> Public Property ArticleMasterData() As ArticleMasterData <JsonProperty(PropertyName:="Stueckliste")> Public Property MaterialCosts() As MaterialCosts <JsonProperty(PropertyName:="Arbeitsgaenge")> Public Property ManufacturingCosts() As ManufacturingCosts End Class Public Class ArticleMasterData <JsonProperty(PropertyName:="Artikelnummer")> Property VPartNumber() As String <JsonProperty(PropertyName:="BezeichnungDE")> Property DesignationDE() As String <JsonProperty(PropertyName:="BezeichnungEN")> Property DesignationEN() As String <JsonProperty(PropertyName:="Einheit")> Property Unit() As String <JsonProperty(PropertyName:="Mat_Grp")> Property MatGrp() As String <JsonProperty(PropertyName:="Kostenart")> Property CostType() As Integer <JsonProperty(PropertyName:="VertriebstextDE")> Property SalesTextDE() As String <JsonProperty(PropertyName:="VertriebstextEN")> Property SalesTextEN() As String <JsonProperty(PropertyName:="Stueckliste")> Property MaterialCosts() As String <JsonProperty(PropertyName:="Status")> Property Status() As String <JsonProperty(PropertyName:="Klasse")> Property ClassName() As String <JsonProperty(PropertyName:="Mantelflaeche")> Property Sheathing() As Double <JsonProperty(PropertyName:="Gewicht")> Property Weight() As Double <JsonProperty(PropertyName:="KlasseID")> Property ClassID() As String End Class Public Class MaterialCosts <JsonProperty(PropertyName:="Verkaufsartikel")> Property VPartNumber() As String <JsonProperty(PropertyName:="Position")> Property Position() As Integer <JsonProperty(PropertyName:="PosArtikel")> Property PosVpart() As String <JsonProperty(PropertyName:="PosBezeichnung")> Property PosDesignation() As String <JsonProperty(PropertyName:="PosKostenart")> Property PosCostType() As Integer <JsonProperty(PropertyName:="Datum")> Property FiledDate() As Date <JsonProperty(PropertyName:="Material")> Property Material() As Double <JsonProperty(PropertyName:="GMK")> Property GMK() As Double <JsonProperty(PropertyName:="Lohn")> Property Wage() As Double <JsonProperty(PropertyName:="Menge")> Property Unit() As Double <JsonProperty(PropertyName:="Mengeneinheit")> Property UnitOfMeasure() As String End Class Public Class ManufacturingCosts <JsonProperty(PropertyName:="Verkaufsartikel")> Property VPartNumber As String <JsonProperty(PropertyName:="AGNR")> Property AGNR As Integer <JsonProperty(PropertyName:="Bereich")> Property Area As String <JsonProperty(PropertyName:="Lohn")> Property Wage As Double <JsonProperty(PropertyName:="Kostenstelle")> Property CostType As Integer <JsonProperty(PropertyName:="Zeit")> Property Time As Double <JsonProperty(PropertyName:="ARBPLATZ")> Property Workplace As String End Class End Class
And my json-File:
{ "Artikelstammdaten": [{"Artikel": ["VAUBEF0010", "VAUBEF0011", "VAUBEF0015", "VAUBEF0016", "VAUBEF0020", "VAUBEF0025", "VAUBEF0030"]}, {"BezeichnungDE": ["Sammelbandantrieb", "Sammelbandantrieb", "Befuellpunkt einfach Behaelter + Karton", "Befuellpunkt doppelt", "Befuellpunkt doppelt Karton FZPS415", "Befuellpunkt Seitenshutter 1 Stellung", "Befuellpunkt Leistungsshutter"]}, {"BezeichnungEN": ["Collectiong belt drive N50", "Concave collecting belt", "", "Filling point double", "", "", ""]}, {"Einheit": ["STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK"]}, {"Mat_Grp": ["VAU", "VAU", "VAU", "", "VAU", "VAU", "VAU"]}, {"Kostenart":[1500, 1500, 1500, 1500, 1500, 1500, 1500]}, {"Vertriebstext_DE":["*Antrieb, Umlenkungen, Spanner* Elektrische Absicherung + Verkabelung* Elektro-Insallationsmaterial anteilig", "Stück Permatantrieb Mudenband N500 v1,5 EkWbeinhaltet:*Antrieb*Spanner; Umleknteill䮧en inkl. Gel䮤er* Kabelrinne Schaltschrank bis Motor* Starterkombination*", "", "Beinhaltet folgende Teile: *Befüllrcihter, Seitenshutter, Rüttelklemmung, Abdeckungen, FZPS Lichtgitter", "NULL", "NULL", "NULL"]}, {"Vertriebstext_EN":["*Drive, deflections", "Stück Permaantrieb", "", "Includes: *funnel, slide", "", "", ""]}, {"Stueckliste":["VAUBEF0010", "VAUBEF0011", "VAUBEF0015", "VAUBEF0016", "VAUBEF0020", "VAUBEF0025", "VAUBEF0030"]}, {"Status": ["F", "F", "G", "F", "G", "G", "G"]}, {"Klasse": ["VTPIMV", "VTPIMV", "VTPIMV", "VTPIMV", "VTPIMV", "VTPIMV", "VTPIMV"]}, {"Mantelflaeche":[1, 1, 12, 12, 12, 0.5, 0.5]}, {"Gewicht":[120, 120, 500, 500, 500, 20, 30]}, {"KlasseID":["1.2.6.4", "1.2.6.4", "", "2.1.6", "", "", ""]}], "Stueckliste": [{"Verkaufsartikel":["VAUBEF0010", "VAUBEF0010", "VAUBEF0010", "VAUBEF0011", "VAUBEF0011", "VAUBEF0011", "VAUBEF0015", "VAUBEF0015", "VAUBEF0015", "VAUBEF0016", "VAUBEF0016", "VAUBEF0016", "VAUBEF0020", "VAUBEF0020", "VAUBEF0020", "VAUBEF0025", "VAUBEF0025", "VAUBEF0025", "VAUBEF0030", "VAUBEF0030", "VAUBEF0030"]}, {"Position":[10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 25, 10, 20, 30, 10, 20, 30, 10, 20, 30]}, {"PosArtikel":["Z0306251", "Z0072937", "Z0072900", "Z0306251", "Z0072937", "Z0072900", "Z0073240", "Z08636568", "Z0073560", "Z0926005", "Z0907896", "Z0945783", "Z0296202", "Z0073328", "Z0073560", "Z0073240", "Z0175446", "Z0175752", "Z0073240", "Z0175448", "Z0073455"]}, {"PosBezeichnung":["VEL Elektro- Montagematerial anteilig pr", "VEL Kabelrinnenmaterial anteilig pro Ant", "Versorgung Elektrik 60m 4G1,5 Kabel", "VEL Elektro-MOntagematerial anteilig pr", "VEL Kabelrinnenmaterial anteilig pro Ant", "Versorgung Elektrik 60m 4G1,5 Kabel", "Aktor Ventil Kabel", "CANIO 16-32 Fix", "GEhause Befuellungspunkt-Frequenzumrichter", "VEL Befuellpunkt doppelt", "Befuellpunkt Schaltschrank mit PCX, FU", "Bedienpult PCX","Aktor Ventil-Kabel gewichtiet", "CANIO 16-8 Wahl PCX", "Gehaeuse Befuellpunkt Frequenzumrichter", "Aktor Ventil-Kabel", "Halterung fuer GL6-Lichtschranke", "Kabel m12 5m", "Aktor Ventil-Kabel", "Kabel M8 5m", "Sensor-Reedkontakt"]}, {"PosKostenart":[9105, 9105, 9105, 9105, 9105, 9105, 9111, 9103, 9106, 9106, 9106, 9103, 9111, 9101, 9106, 9111, 9110, 9111, 9111, 9111, 9102]}, {"Datum":["2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31", "2022-01-31"]}, {"Material":[60.41, 160.28, 38.68, 60.41, 160,28, 38.68, 12.36, 105.31, 665.99, 3965.23, 3489.32, 1317.19, 41.2, 323.2, 665.99, 4.12, 28.64, 3.68, 8.24, 5.54, 74.06]}, {"GMK":[3.63, 9.62, 2.32, 3.63, 9.62, 2.32, 0.75, 6.32, 39.94, 237.85, 209.37, 79.04, 2.5, 19.4, 39.94, 0.25, 1.76, 0.22, 0.5, 0.34, 4.44]}, {"Lohn":[2.06, 0, 0, 2.06, 0, 0, 0, 19.39 ,229.28, 149.02, 1322.23, 89.21, 0, 32.2, 229.28, 0, 18.32, 0, 0, 0, 0]}, {"Menge":[1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 10, 2, 1, 1, 4, 1, 2, 2, 2]}, {"Mengeneinheit":["STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK", "STK"]}], "Arbeitsgänge": [{"Verkaufsartikel":["VAUBEF0010", "VAUBEF0010", "VAUBEF0010", "VAUBEF0011", "VAUBEF0011", "VAUBEF0011", "VAUBEF0015", "VAUBEF0015", "VAUBEF0015", "VAUBEF0016", "VAUBEF0016", "VAUBEF0016", "VAUBEF0020", "VAUBEF0020", "VAUBEF0020", "VAUBEF0025", "VAUBEF0025", "VAUBEF0025", "VAUBEF0030", "VAUBEF0030", "VAUBEF0030"]}, {"AGNR":[10, 20, 6, 10, 20, 6, 10, 100, 20, 10, 100, 110, 10, 100, 20, 10, 100, 30, 10, 100, 30]}, {"Bereich":["Mechanische Montage", "Elektrische Montage", "TF - Mechanik", "TF - Elektrik", "Mechanische Montage", "Elektrische Montage", "Elektrische Montage", "Mechanische Montage", "Systembau Stationsabnahme QS", "Elektrische Montage", "Mechanische Montage", "Stationsabnahme Stationsabnahme QS", "Systembau Verpacken", "Mechanische Montage", "Systembau Stationsabnahme QS", "Elektrische Montage", "Systembau Mechanik Stationsaufbau", "Mechanische Montage", "Systembau Mechanik Stationsaufbau", "Systembau Stationsabnahme QS", "Mechanische Montage"]}, {"Lohn":[89.1, 160.38, 168, 106.92, 160.38, 168, 320.76, 9.8583, 213.84, 427.79988, 21.1, 100, 427.68, 19.71665, 213.84, 61.5, 2.75, 16.2, 25.625, 2.766665, 16.2]}, {"Kostenstelle":[523500, 523500, 522000, 523500, 523500, 522000, 523500, 906045, 523500, 523500, 906045, 906045, 523500, 906045, 523500, 906045, 906045, 523500, 906056, 906045, 523500]}, {"Zeit":[148.5, 267.3, 180, 178.2, 267.3, 180, 534.6, 11.83, 356.4, 713, 25.32, 120, 712.8, 23.66, 356.4, 73.8, 3.3, 27, 30.75, 3.32, 27]}, {"ARBPLATZ":["K950M", "K950E", "K420M", "K950M", "K950E", "K420M", "K950M", "683SAB", "K950E", "K950M", "683SAB", "683V", "K950M", "683SAB", "K950E", "683", "683SAB", "K950M", "683", "683SAB", "K950M"]}] }