Being a VB.Net programmer using VB.Net 2015 community, I come across items in C# that I need to convert to VB, but this time I don't understand what I'm working with. The website service I'm consuming returns and expects JSON / JOBJECTS structures like:
var token = new {
iss = PARTNERID,
product = "twpemp",
sub = "partner",
siteInfo = new {
type = "id",
id = SITEID
},
exp = (Int32)DateTime.UtcNow.Add(new TimeSpan(0, 4, 30)).Subtract(new DateTime(1970, 1, 1)).TotalSeconds
};
An online converter converted this into:
Dim EPochTime = DateTime.UtcNow.Add(New TimeSpan(0, 4, 0)).Subtract(New DateTime(1970, 1, 1)).TotalSeconds
Dim Token = New With {
Key .iss = AccNumber,
Key .product = "twppartner",
Key .sub = "partner",
Key .siteInfo = New With {
Key .type = "id",
Key .id = Site},
Key .exp = EPochTime
}
I need to dynamically create this type of structures because the "key name" and values change depending on what was returned and needs to be sent back. For example, depending on the siteid from above, the returning structure might have stuff like:
"Results": [
{
"RecordNumber": 000001,
"EmployeeCode": "0001",
"FirstName": "John",
"MiddleName": "A",
"LastName": "Dow",
"Designation": "Worker",
"Home1": "Press",
},
{
"RecordNumber": 000002,
"EmployeeCode": "0002",
"FirstName": "Jane",
"MiddleName": "b",
"LastName": "Dow",
"Designation": "Helper",
"Home1": "Office",
}
}
For the next client I submit a query for, and eventually need to update with might have:
"Results": [
{
"RecordNumber": 12345,
"EmployeeCode": "231",
"FirstName": "Erick",
"MiddleName": "G",
"LastName": "Smith",
"Department": "Electrial",
},
{
"RecordNumber": 732456,
"EmployeeCode": "853",
"FirstName": "Fred",
"MiddleName": "W",
"LastName": "Kerber",
"Department": "Electrial",
}
}
The difference between the two is one has "Department" and the other doesn't. This structure changes based on the siteID from the first call.
My main question is how do I create something like this dynamically in VB.NET, and secondarily, exactly what is this type of thing called? I'm calling it a structure for lack of better words.