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 01 '22 edited Jun 01 '22
I realized my simulation was solving an earlier question where you needed arrays of arrays and I don't think it works here.
This is the class structure I generated from your original Json:
Is that still correct? If so, when you deserialize, do you get a List(Of RootObject.Rootobject)? Then you create some queries that return List(Of Artikelstammdaten ()) etc? And you want to create an IList of what, every instance of Artikelstammdaten across all instances of RootObject.Rootobject? Or something else?