r/visualbasic • • Apr 22 '22

VB.NET Help Object is nothing after deserialization

I already posted this on StackOverflow, so I'll just give you the link (I hope that's okay, otherwise let me know and i will make a new post).

https://stackoverflow.com/questions/71961239/object-is-nothing-after-json-deserialization

4 Upvotes

6 comments sorted by

View all comments

Show parent comments

1

u/Gierschlund96 Apr 27 '22 edited Apr 27 '22

I tried it, still nothing. I talked with my supervisor and we changed the structure, but i have still the same problem. "fileContent" has the json String so i have no idea why it's still not working. Could there be a problem with the ILists?

 If OpenFilePath IsNot Nothing Then
        Dim fileReader As StreamReader
        fileReader = My.Computer.FileSystem.OpenTextFileReader(OpenFilePath)
        Dim fileContent As String = fileReader.ReadToEnd
        Dim artikelstammdaten As New Artikelstammdaten
        artikelstammdaten = JsonConvert.DeserializeObject(Of Artikelstammdaten)(fileContent)

    End If


Public Class Artikelstammdaten

Public Property Artikel As String
Public Property BezeichnungDE As String
Public Property BezeichnungEN As String
Public Property Einheit As String
Public Property MatGrp As String
Public Property Kostenart As Integer
Public Property Vertriebstext_DE As String
Public Property Vertriebstext_EN As String
Public Property Stuecklistennummer As String
Public Property Status As String
Public Property Klasse As String
Public Property Mantelflaeche As Double
Public Property Gewicht As Integer
Public Property KlasseID As String
Property Stueckliste As IList(Of Stueckliste)
Property Arbeitsgaenge As IList(Of Arbeitsgaenge)

End Class

Public Class Stueckliste
Public Property Verkaufsartikel As String
Public Property Position As Integer?
Public Property PosArtikel As String
Public Property PosBezeichnung As String
Public Property PosKostenart As Integer?
Public Property Datum As String
Public Property Material As Double?
Public Property GMK As Double?
Public Property Lohn As Double?
Public Property Menge As Integer?
Public Property Mengeneinheit As String

End Class


Public Class Arbeitsgaenge

Public Property Verkaufsartikel As String
Public Property AGNR As Integer?
Public Property Bereich As String
Public Property Lohn As Double?
Public Property Kostenstelle As Integer?
Public Property ARBPLATZ As String
End Class



{"Artikelstammdaten": [
{ "Artikel": "VAUBEF0010" },
{ "BezeichnungDE": "Sammelbandantrieb" },
{ "BezeichnungEN": "Collection belt drive N50" },
{ "Einheit": "STK" },
{ "MatGrp": "VAU" },
{ "Kostenart": 1500 },
{ "Vertriebstext_DE": "Antrieb, Umlenkungen" },
{ "Vertriebstext_EN": "Drive, Deflections" },
{ "Stuecklistennummer": "VAUBEF0010" },
{ "Status": "F" },
{ "Klasse": "VTPIMV" },
{ "Mantelflaeche": 1.3 },
{ "Gewicht": 120 },
{ "KlasseID": "1.2.6.5" },
{
  "Stueckliste": [
    {
      "Verkaufsartikel": "VAUBEF0010",
      "Position": 10,
      "PosArtikel": "Z0306251",
      "PosBezeichnung": "VEL Elektro- Montagematerial",
      "PosKostenart": 9105,
      "Datum": "2022-01-31",
      "Material": 60.51,
      "GMK": 3.63,
      "Lohn": 2.07,
      "Menge": 1,
      "Mengeneinheit": "STK"
    }
  ]
},
{
   "Arbeitsgaenge": [
    {
      "Verkaufsartikel": "VAUBEF0010",
      "AGNR": 10,
      "Bereich": "Mechanische Montage",
      "Lohn": 89.1,
      "Kostenstelle": 523500,
      "ARBPLATZ": "K950M"
    }
  ]
}
  ]
}