I currently am trying to deserialize a JSON-object to a VB.NET-object. But I am not able to do that properly - but I guess I know the reason for it. Here is an example of my JSON-object:
{
"USERNAME1": [
{
"workingTimes": [
{
"endDateAndTime": "20250524T105500Z",
"beginDateAndTime": "20250524T102600Z",
"workingTimeType": {
"type": "wTime",
"name": "wTime"
},
"name": "wTime",
"type": "wTime",
"id": "1"
}
],
"beginDate": "2025-01-01",
"targetWorkingTimeMinutes": 0,
"breakDurationMinutes": 0,
"workingTimeMinutes": 20,
"endDate": "2025-01-01"
}
]
}
And my classes currently are:
Public Class COLLECTION
Public Property USERS As New List(Of WORKDAY)
End Class
Public Class WORKDAY
Public workingTimes As New List(Of WORKTIME)
Public beginDate As String
Public targetWorkingTimeMinutes As String
Public breakDurationMinutes As String
Public workingTimeMinutes As String
Public endDate As String
End Class
Public Class WORKTIME
Public endDateAndTime As String
Public beginDateAndTime As String
Public workingTimeType As WORKTIMETYPE
Public name As String
Public type As String
Public id As String
End Class
Public Class WORKTIMETYPE
Public type As String
Public name As String
End Class
When I try to deserialize the JSON to my classes I just get errors. But I am sure that is caused because of the USERNAME1 that is a variable name and not a specified object (and yes, there can be multiple entries)!
If I change "Public Property USERS As New List(Of WORKDAY)" to "Public Property USERSNAME1 As New List(Of WORKDAY)" all seems to work fine!
I am a pretty newbie in JSON but I also tried to create a JSON using my classes and the result looks exactly like my example. So USERNAME1 must be the reason for my problems.
Public Property USERNAME1 As USERNAME1()but the querent needs to handle variable names. The already triedPublic Property USERSNAME1 As New List(Of WORKDAY)and know it works, but that doesn't meet their needs.USERNAME1in the JSON seems to indicate that entry is for a single user. Whereas, the usage ofUSERSin the VB.NET code, seems to indicate that the JSON may contain more than one user which means that the OP needs to include a better JSON example (ie: more data).