r/visualbasic • u/Gierschlund96 • May 05 '22
VB.NET Help Is it possible to seperate one Json-File into different objects?
I have three XamDataGrids, each one has to show different data but from the same json-File. For the first XamDataGrid i set the DataSource to the deserialized object (that's fine, it shows the correct data), but for the other both I just need a snipped of data.
If OpenFilePath IsNot Nothing Then
Dim fileReader As StreamReader
fileReader = My.Computer.FileSystem.OpenTextFileReader(OpenFilePath)
Dim fileContent As String = fileReader.ReadToEnd
Dim root = JsonConvert.DeserializeObject(fileContent, GetType(List(Of Artikelstammdaten)))
dgArticleMasterData.DataSource = CType(root, IEnumerable)
dgMaterialCosts.DataSource = ??
dgManufacutringCosts.DataSource = ??
End Ifthe json looks like this (i need the data from "Stueckliste" for dgMaterialCosts and "Arbeitsgaenge" for dgManufacturingCosts):
[
{
"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": "VPTIMV",
"Mantelflaeche": 1.3,
"Gewicht": 120.0,
"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"
}
]
}]
Changing the json structure is not an option. Thanks for your help'!
1
Upvotes
View all comments
Show parent comment
1
u/RJPisscat Jun 02 '22
Inside the If: Change allStueckliste back to listStueckliste, which is probably supposed to be empty when you start the inner loop if not the outer loop.
KEEP allStueckliste as the collection in the inner For loop.