Hello,
I've encountered an issue that I am stuck on. So I'm attempting to deserialize 2 object lists from a Json File, the first one comes out fine but on creating a new object in the list for the second object list, a full null object is sent through the new constructor of the object. I could handle it but I don't know the break statement equivalent for a constructor. There's a lot of parts to my code so I'll only send the most important parts, if you need more please ask.
Thank you,
Connor Frayne
Below is the Json file and code.
Public Class Form1
Public Profiles As ProfilesList
Public FIDs As FIDsList
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim JsonPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "SafeBox Config", "SBGUIElements.json")
Try
Dim jsonFromFile As String = System.IO.File.ReadAllText(JsonPath)
Profiles = JsonConvert.DeserializeObject(Of ProfilesList)(jsonFromFile)
jsonFromFile = System.IO.File.ReadAllText(JsonPath)
FIDs = JsonConvert.DeserializeObject(Of FIDsList)(jsonFromFile)
Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try
'a Few other things
end sub
end class
Public Class FIDsList
Public Property FIDs As List(Of FID)
End Class
Public Class ProfilesList
Public Property Profiles As List(Of Profile)
End Class
Public Class Profile
Public Property MasterNum As Integer
Public Property Name As String
<[JsonIgnore]> Public Property State As String
Get
Return _State
End Get
Set(ByVal value As String)
If Not value Is State Then
_State = value
End If
End Set
End Property
Private _State As String
Public Property Location As String
Public Property ProfInfo As String
<[JsonIgnore]> Public Property FaultInfo As String
<[JsonIgnore]> Public chk_chkbox As New CheckBox
<[JsonIgnore]> Public InProfFIDHandler As EventHandler
Public Sub New(ByVal new_MasterNum As Integer, ByVal new_Name As String, ByVal new_State As String,
ByVal new_Location As String, ByVal new_ProfInfo As String, ByVal new_FaultInfo As String)
MasterNum = new_MasterNum
Name = new_Name
State = new_State
Location = new_Location
ProfInfo = new_ProfInfo
FaultInfo = new_FaultInfo
End Sub
end class
Public Class FID
Public Property Master As Profile
Public Property FIDNum As Integer
Public Property Name As String
<[JsonIgnore]> Public Property State As String
Get
Return _State
End Get
Set(value As String)
_State = value
‘FIDStateChanged()
End Set
End Property
Private _State As String
Public Property Location As String
<[JsonIgnore]> Public InFIDHandler As EventHandler
<[JsonIgnore]> Public Pic_FID As PictureBox
Public Sub New(ByRef new_Master As Profile, ByVal new_FIDNum As Integer, ByVal new_Name As String,
ByVal new_State As String, ByVal new_Location As String)
Master = new_Master
FIDNum = new_FIDNum
Name = new_Name
State = new_State
Location = new_Location
‘AddHandler Pic_FID.Click, AddressOf FID_Click
End Sub
‘Some other things
End class
{
"Profiles": [
{
"MasterNum": 1,
"Name": "Master1",
"Location": "Floor - 1",
"ProfInfo": "Master for FID 1, 2, 3, 6."
},
{
"MasterNum": 2,
"Name": "Master2",
"Location": "Floor - 2",
"ProfInfo": "Master for FID 4, 5."
},
{
"MasterNum": 3,
"Name": "MMMMMMMMMMMMMMM",
"Location": "Floor - 1",
"ProfInfo": "Master for FID 7"
},
{
"MasterNum": 4,
"Name": "Master4",
"Location": "Floor - 2",
"ProfInfo": "Master for FID 8"
},
{
"MasterNum": 5,
"Name": "Master5",
"Location": "Floor - 1",
"ProfInfo": "Master for FID 9"
},
{
"MasterNum": 6,
"Name": "Master6",
"Location": "Floor - 2",
"ProfInfo": "Master for FID 10, 11, 12"
}
],
"FIDs": [
{
"Master": {
"MasterNum": 1,
"Name": "Master1",
"Location": "Floor - 1",
"ProfInfo": "Master for FID 1, 2, 3, 6."
},
"FIDNum": 1,
"Name": "FID1",
"Location": "Floor - 1"
},
{
"Master": {
"MasterNum": 1,
"Name": "Master1",
"Location": "Floor - 1",
"ProfInfo": "Master for FID 1, 2, 3, 6."
},
"FIDNum": 2,
"Name": "FID2",
"Location": "Floor - 1"
},
{
"Master": {
"MasterNum": 1,
"Name": "Master1",
"Location": "Floor - 1",
"ProfInfo": "Master for FID 1, 2, 3, 6."
},
"FIDNum": 3,
"Name": "FID3",
"Location": "Floor - 1"
},
{
"Master": {
"MasterNum": 2,
"Name": "Master2",
"Location": "Floor - 2",
"ProfInfo": "Master for FID 4, 5."
},
"FIDNum": 4,
"Name": "FID4",
"Location": "Floor - 2"
},
{
"Master": {
"MasterNum": 2,
"Name": "Master2",
"Location": "Floor - 2",
"ProfInfo": "Master for FID 4, 5."
},
"FIDNum": 5,
"Name": "FID5",
"Location": "Floor - 2"
},
{
"Master": {
"MasterNum": 1,
"Name": "Master1",
"Location": "Floor - 1",
"ProfInfo": "Master for FID 1, 2, 3, 6."
},
"FIDNum": 6,
"Name": "FID6",
"Location": "Floor - 2"
},
{
"Master": {
"MasterNum": 3,
"Name": "MMMMMMMMMMMMMMM",
"Location": "Floor - 1",
"ProfInfo": "Master for FID 7"
},
"FIDNum": 7,
"Name": "FID7",
"Location": "Floor - 1"
},
{
"Master": {
"MasterNum": 4,
"Name": "Master4",
"Location": "Floor - 2",
"ProfInfo": "Master for FID 8"
},
"FIDNum": 8,
"Name": "FID8",
"Location": "Floor - 2"
},
{
"Master": {
"MasterNum": 5,
"Name": "Master5",
"Location": "Floor - 1",
"ProfInfo": "Master for FID 9"
},
"FIDNum": 9,
"Name": "FID9",
"Location": "Floor - 1"
},
{
"Master": {
"MasterNum": 6,
"Name": "Master6",
"Location": "Floor - 2",
"ProfInfo": "Master for FID 10, 11, 12"
},
"FIDNum": 10,
"Name": "FID10",
"Location": "Floor - 2"
},
{
"Master": {
"MasterNum": 6,
"Name": "Master6",
"Location": "Floor - 2",
"ProfInfo": "Master for FID 10, 11, 12"
},
"FIDNum": 11,
"Name": "FID11",
"Location": "Floor - 2"
},
{
"Master": {
"MasterNum": 6,
"Name": "Master6",
"Location": "Floor - 2",
"ProfInfo": "Master for FID 10, 11, 12"
},
"FIDNum": 12,
"Name": "FID12",
"Location": "Floor - 2"
}
]
}