I'm using JSON.NET to deserialize JSON responses from HTTP queries, but I'm stuck with an issue. That's because the response can send two types of object under same property, as shown below:
1st case sample (most common):
{
"type": "myType",
"tid": 4,
"action": "myAction",
"method": "myMethod",
"result": {
"success": true,
"total": 4,
"records": [
{
"id": 4,
"nome": "PRIMEIRO NOME",
"sigla": "PN"
},
{
"id": 1974,
"nome": "SEGUNDO NOME",
"sigla": "SN"
},
{
"id": 2584,
"nome": "TERCEIRO NOME",
"sigla": "TN"
},
{
"id": 1170,
"nome": "QUARTO NOME",
"sigla": "QN"
}
]
}
}
2nd case sample (rare):
{
"type": "myType",
"tid": 3,
"action": "myAction",
"method": "myMethod",
"result": [
{
"id": 4,
"nome": "PRIMEIRO NOME",
"sigla": "PN"
},
{
"id": 1974,
"nome": "SEGUNDO NOME",
"sigla": "SN"
},
{
"id": 2584,
"nome": "TERCEIRO NOME",
"sigla": "TN"
},
{
"id": 1170,
"nome": "QUARTO NOME",
"sigla": "QN"
}
]
}
I've been using these classes to receive data for the 1st case:
Public Class Record
Public Property id As Integer
Public Property nome As String
Public Property sigla As String
End Class
Public Class Result
Public Property success As Boolean
Public Property total As Integer
Public Property records As Record()
End Class
Public Class Response
Public Property type As String
Public Property tid As Integer
Public Property action As String
Public Property method As String
Public Property result As Result
End Class
So it worked well upon deserialization of 1st case JSON, with this statement:
Dim myResponse = JsonConvert.DeserializeObject(Of Response)(myJsonString)
However, when receiving 2nd case JSON, it creates object of type Response, stores in its property result an object of type Result whose properties remain empty, and the data which I needed to retrieve vanishes for it is stored nowhere.
I thought that I should modify the class Response so it has place for that different set of data, this way:
Public Class Response
Public Property type As String
Public Property tid As Integer
Public Property action As String
Public Property method As String
Public Property result As Result
Public Property resultRecords As Record()
End Class
The question, then, is this: how can I tell JsonConvert whether to store data in property Response.result when it fits its type (1st sample case above), or in Response.resultRecords in 2nd case?
Thank you!
Since the format of the JSON can vary for the same property, you will need a custom JsonConverter to handle it. The converter can read the JSON for the affected property, determine its format and then populate your objects appropriately. Here is the code you would need:
Public Class ResultConverter
Inherits JsonConverter
Public Overrides Function CanConvert(objectType As Type) As Boolean
Return objectType = GetType(Result)
End Function
Public Overrides Function ReadJson(reader As JsonReader, objectType As Type, existingValue As Object, serializer As JsonSerializer) As Object
Dim token As JToken = JToken.Load(reader)
Dim result As Result = New Result
If token.Type = JTokenType.Array Then
result.records = token.ToObject(Of Record())(serializer)
result.total = result.records.Length
result.success = True
Else
serializer.Populate(token.CreateReader(), result)
End If
Return result
End Function
Public Overrides ReadOnly Property CanWrite As Boolean
Get
Return False
End Get
End Property
Public Overrides Sub WriteJson(writer As JsonWriter, value As Object, serializer As JsonSerializer)
Throw New NotImplementedException
End Sub
End Class
To use the converter, add a <JsonConverter> attribute to the result property in your Response class:
Public Class Response
Public Property type As String
Public Property tid As Integer
Public Property action As String
Public Property method As String
<JsonConverter(GetType(ResultConverter))>
Public Property result As Result
End Class
Here is a working fiddle to show that this converter will allow both JSON formats to be deserialized into the same classes: https://dotnetfiddle.net/NFbQ2Q
Related
I'm having an issue with a JSON property name. It might be because I don't know what I'm doing. This is my 1st attempt at serializing JSON (with vb.net VB)
The result I'm looking for is this:
{
"login": {
"username": "XXX",
"password": "pwxXXxx",
"busId": "123456789",
"busRole": "Third Party",
"paymentTerms": "Prepaid"
}
}
This is what I am getting:
[
{
"login": null,
"username": "1234",
"password": "pw123456",
"busId": "12345",
"busRole": "Third Party",
"paymentTerms": "Prepaid"
}
]
My issue is with the piece "login": {" adds the colon and the term null. I'll post my code below
Any help would be appreciated.
-Thank You
Partial Class _Default
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim loads As New List(Of fgtload)()
loads.Add(New fgtload() With {
.username = "1234",
.password = "pw123456",
.busId = "12345",
.busRole = "Third Party",
.paymentTerms = "Prepaid"
}
)
Dim strserialize As String = JsonConvert.SerializeObject(loads)
lblserial.Text = strserialize
End Sub
Public Class fgtload
<JsonProperty(PropertyName:="login")>
Public Property login As String
Public Property username() As String
Get
Return m_username
End Get
Set
m_username = Value
End Set
End Property
Private m_username As String
Public Property password() As String
Get
Return m_password
End Get
Set
m_password = Value
End Set
End Property
Private m_password As String
Public Property busId() As String
Get
Return m_busId
End Get
Set
m_busId = Value
End Set
End Property
Private m_busId As String
Public Property busRole() As String
Get
Return m_busRole
End Get
Set
m_busRole = Value
End Set
End Property
Private m_busRole As String
Public Property paymentTerms() As String
Get
Return m_paymentTerms
End Get
Set
m_paymentTerms = Value
End Set
End Property
Private m_paymentTerms As String
End Class
Here's the entire JSON output sampel Im trying to get.
{
"login": {
"username": "XXX",
"password": "pwxXXxx",
"busId": "123456789",
"busRole": "Third Party",
"paymentTerms": "Prepaid"
}
}
,
"details": {
"serviceClass": "STD",
"typeQuery": "QUOTE",
"pickupDate": "20200221",
"productCode": "DFQ"
},
"originLocation": {
"city": "Keyport",
"state": "NJ",
"postalCode": "07735",
"country": "USA",
"locationType": "COMM"
},
"destinationLocation": {
"city": "Beverly Hills",
"state": "CA",
"postalCode": "90210",
"country": "USA",
"locationType": "COMM"
},
"listOfCommodities": {
"commodity": [
{
"packageLength": 48,
"packageWidth": 48,
"packageHeight": 48,
"weight": 1500,
"handlingUnits": 1,
"packageCode": "PLT"
}
]
}
}
How would I add another class to the wrapper. For example
Public Class fgtDetails '
Public ServiceClass As String
Public typeQuery As String
Public pickupDate As Integer
Public productCode As String
End Class
From what I can see, you are trying to declare the login element as an empty string and is therefore serialized as null. From what you said you are trying to achieve, you want to declare login as an object that contains the Username, Password, BusID, BusRole, and PaymentTerms properties.
From what your looking for, the Login property is an object, but you are declaring it as a string. Also, you are creating a list and serializing that, which is leading to those square brackets ([, ]) around your JSON. Square brackets mark arrays or enumerations, whereas in your sample JSON you are just looking for an object.
One last tip, for classes that are used for serializing, you don't have to use properties. You can just declare your variables as public variables. The only time you need to use properties is if you need to modify or do something with its contents when it's being set or read. e.g., formatting a string when it's being set, or calculating a response when the variable is being retrieved (you can put code in the GET and SET methods to make them act like a function).
Something to note with serializing and deserializing, you can nest classes. When serialized they will be converted to JSON objects using the same object layout and variable name. So you can try something like this:
(UPDATED CODE)
Public Sub CreateJson()
'Create Wrapper Object
Dim Load As New fgtload
Load.Login = New fgtLoginData With { 'Create Login Data
.Username = "XXX",
.Password = "pwxXXxx",
.BusID = 123456789,
.BusRole = "Third Party",
.PaymentTerms = "Prepaid"
}
Load.Details = New fgtDetailsData With { 'Create Details
.ServiceClass = "STD",
.TypeQuery = "QUOTE",
.PickupDate = "20200221",
.ProductCode = "DFQ"
}
Load.OriginLocation = New fgtLocationnData With { 'Create Origin
.City = "Keyport",
.State = "NJ",
.PostalCode = 7735,
.Country = "USA",
.LocationType = "COMM"
}
Load.DestinationLocation = New fgtLocationnData With { 'Create Destination
.City = "Beverly Hills",
.State = "CA",
.PostalCode = 90210,
.Country = "USA",
.LocationType = "COMM"
}
'Create Commodities
Dim Commodity1 As New fgtCommodity With {
.PackageLength = 48,
.PackageWidth = 48,
.PackageHeight = 48,
.Weight = 1500,
.HandlingUnits = 1,
.PackageCode = "PLT"
}
'Add commodity to load
Load.ListOfCommodities.commodity.Add(Commodity1)
'Serialize wrapper object
Dim Json As String = JsonConvert.SerializeObject(Load)
End Sub
Public Class fgtload 'Primary wrapper
Public Login As New fgtLoginData
Public Details As New fgtDetailsData
Public OriginLocation As New fgtLocationnData
Public DestinationLocation As New fgtLocationnData
Public ListOfCommodities As New fgtCommodityWrapper
End Class
Public Class fgtLoginData 'Login Data
Public Username As String
Public Password As String
Public BusID As String
Public BusRole As String
Public PaymentTerms As String
End Class
Public Class fgtDetailsData 'Details Data
Public ServiceClass As String
Public TypeQuery As String
Public PickupDate As String
Public ProductCode As String
End Class
Public Class fgtLocationnData 'Location data for both Origin and Destination
Public City As String
Public State As String
Public PostalCode As String
Public Country As String
Public LocationType As String
End Class
Public Class fgtCommodityWrapper 'Commodity Data
Public commodity As New List(Of fgtCommodity) ' Lists get serialized into arrays
End Class
Public Class fgtCommodity
Public PackageLength As Double 'Doubles to allow floating-point numbers
Public PackageWidth As Double
Public PackageHeight As Double
Public Weight As Double
Public HandlingUnits As Integer
Public PackageCode As String
End Class
This creates this response.
(UPDATED OUTPUT)
{
"Login": {
"Username": "XXX",
"Password": "pwxXXxx",
"BusID": "123456789",
"BusRole": "Third Party",
"PaymentTerms": "Prepaid"
},
"Details": {
"ServiceClass": "STD",
"TypeQuery": "QUOTE",
"PickupDate": "20200221",
"ProductCode": "DFQ"
},
"OriginLocation": {
"City": "Keyport",
"State": "NJ",
"PostalCode": "7735",
"Country": "USA",
"LocationType": "COMM"
},
"DestinationLocation": {
"City": "Beverly Hills",
"State": "CA",
"PostalCode": "90210",
"Country": "USA",
"LocationType": "COMM"
},
"ListOfCommodities": {
"commodity": [
{
"PackageLength": 48.0,
"PackageWidth": 48.0,
"PackageHeight": 48.0,
"Weight": 1500.0,
"HandlingUnits": 1,
"PackageCode": "PLT"
}
]
}
}
Hope this helps.
(UPDATE NOTES):
In response to your comment, I have modified the code in my response to allow or your updated expected output.
Note also that if two JSON objects have the same structure (in this case originLocation and destinationLocation) you can use the same class.
Also, see at the Commodity Data there are square brackets, this marks a JSON array. Arrays/Lists/Enumerations in your code will be serialized into JSON arrays, even if they are of a class type. So in this code example, you can add as many commodities to ListOfCommodities.commodity as you want and they will be properly serialized into JSON.
Json string is not deserialsing correctly
have played around with my classes etc, but bfevent always returns Nothing
have tried Public Property bfevent As BFEvent() in case it needs to be able to take multi values
pretty sure it's something simple....
strcatalogue = "{ "jsonrpc": "2.0", "result": [{ "event": { "id": "29202748", "name": "Kings XI Punjab v Mumbai Indians", "countryCode": "GB", "timezone": "GMT", "openDate": "2019-03-30T10:30:00.000Z" }, "marketCount": 20 }, { "event": { "id": "29201119", "name": "Victoria v NSW Blues", "countryCode": "AU", "timezone": "GMT", "openDate": "2019-03-27T23:30:00.000Z" }, "marketCount": 2 }, { "event": { "id": "29202753", "name": "Chennai Super Kings v Rajasthan Royals", "countryCode": "GB", "timezone": "GMT", "openDate": "2019-03-31T14:30:00.000Z" }, "marketCount": 35 }], "id": 1 }"
Dim objJson = JsonConvert.DeserializeObject(Of BFEventList)(strCatalogue)
Public Class BFEvent
Public Property id As String
Public Property name As String
Public Property countryCode As String
Public Property timezone As String
Public Property openDate As DateTime
End Class
Public Class BFResult
Public Property bfevent As BFEvent
Public Property marketCount As Integer
End Class
Public Class BFEventList
Public Property jsonrpc As String
Public Property result As BFResult()
Public Property id As Integer
End Class
BFEvent = Nothing
marketCount works fine, so something to do with BFEvents class
So i renamed my class to refer to the actual string values in the json. So bfevent is now event. I'm not sure if this is 'required' or not. Will test that elsewhere where i have working code.
But am now getting 'Keyword is not a valid identifier' for
Public Property Event As BFEvent()
with Event underlined.
No errors here
Dim Name As String = objJson.result(0).Event(0).name
But cannot compile due to above error
I've being spending a lot of time thinking about how to iterate an object from a deserealized json which has many items, subitems and sub-subitems. I know there are a lot of questions already posted, but I still don't get it, 'cause the examples are differrents to mine and I'm a begineer developper. I get the Json from a Web Service and I pass the Token by headers and all that stuff, but I don't know the best way to manipulate this info. I'm using Newtonsoft library, BTW.
The Json is:
{
"orders": [
{
"customer": {
"id": "string",
"externalId": "string",
"firstName": "string",
"lastName": "string",
"name": "string",
"companyName": "string",
"emailAddresses": [
"string"
],
"phones": [
{
"type": "Mobile",
"number": "string"
}
],
"addresses": [
{
"lines": [
"string"
],
"locality": [
"string"
],
"region": "string",
"postcode": "string"
}
]
},
"vehicles": [
{
"id": "string",
"description": "string",
"vin": "string",
"odometer": 0,
"tag": "string",
"nextServiceDue": "2015-07-14T10:08:15Z",
"registrationTestDue": "2015-07-14T10:08:15Z",
"brand": "string",
"extendedWarrantyEndDate": 0,
"contractEndDate": 0,
"transmissionCode": "string",
"engineCode": "string",
"bodyType": "string",
"paintCode": "string",
"modelCode": "string",
"references": [
{
"key": "string",
"value": "string"
}
]
}
],
"employees": [
{
"id": "string",
"name": "string",
"type": "Technician"
}
],
"operations": [
{
"id": "35955",
"code": "RWB",
"externalCode": "RACS",
"description": "431151: Front Shock Absorber Assembly (One Side), Repair/Replace",
"isNew": true,
"labour": {
"pricing": {
"totals": {
"total": 0
}
},
"times": [
{
"quantity": 1.2
}
]
}
}
],
"parts": [
{
"number": "string",
"quantity": 1,
"quantityUnitOfMeasure": "Hour",
"description": "string",
"vehicleId": "string",
"pricing": {
"totals": {
"total": 0
}
}
}
]
}
],
"paging": {
"page": 0,
"morePages": true,
"resultCount": 0,
"pageCount": 0
}
}
And the Code for getting the json properties is:
Public Class Rootobject
Public Property orders() As Order
Public Property paging As Paging
End Class
Public Class Paging
Public Property page As Integer
Public Property morePages As Boolean
Public Property resultCount As Integer
Public Property pageCount As Integer
End Class
Public Class Order
Public Property customer As Customer
Public Property vehicles() As Vehicle
Public Property employees() As Employee
Public Property operations() As Operation
Public Property parts() As Part
End Class
Public Class Customer
Public Property id As String
Public Property externalId As String
Public Property firstName As String
Public Property lastName As String
Public Property name As String
Public Property companyName As String
Public Property emailAddresses() As String
Public Property phones() As Phone
Public Property addresses() As Address
End Class
Public Class Phone
Public Property type As String
Public Property number As String
End Class
Public Class Address
Public Property lines() As String
Public Property locality() As String
Public Property region As String
Public Property postcode As String
End Class
Public Class Vehicle
Public Property id As String
Public Property description As String
Public Property vin As String
Public Property odometer As Integer
Public Property tag As String
Public Property nextServiceDue As Date
Public Property registrationTestDue As Date
Public Property brand As String
Public Property extendedWarrantyEndDate As Integer
Public Property contractEndDate As Integer
Public Property transmissionCode As String
Public Property engineCode As String
Public Property bodyType As String
Public Property paintCode As String
Public Property modelCode As String
Public Property references() As Reference
End Class
Public Class Reference
Public Property key As String
Public Property value As String
End Class
Public Class Employee
Public Property id As String
Public Property name As String
Public Property type As String
End Class
Public Class Operation
Public Property id As String
Public Property code As String
Public Property externalCode As String
Public Property description As String
Public Property isNew As Boolean
Public Property labour As Labour
End Class
Public Class Labour
Public Property pricing As Pricing
Public Property times() As Time
End Class
Public Class Pricing
Public Property totals As Totals
End Class
Public Class Totals
Public Property total As Integer
End Class
Public Class Time
Public Property quantity As Single
End Class
Public Class Part
Public Property number As String
Public Property quantity As Integer
Public Property quantityUnitOfMeasure As String
Public Property description As String
Public Property vehicleId As String
Public Property pricing As Pricing1
End Class
Public Class Pricing1
Public Property totals As Totals1
End Class
Public Class Totals1
Public Property total As Integer
End Class
And I deserealize the Json and i've traying this, an example:
Dim JsonObject As List(Of Rootobject) = JsonConvert.DeserializeObject(Of List(Of Rootobject))(_JsonString)
For Each item In JsonObject
_PagPage = item.paging.page
_PagMorePag = item.paging.morePages
_PagResCount = item.paging.resultCount
_PagPagCount = item.paging.pageCount
Next
I tried to use Lists like List(Of Rootobject) or List(Of List(Of Dictionary(Of Rootoobject)), but it's still not working.
If you could to help me out i'd really appreciate it.
I'm using RestTemplate to retrieve list of issues from Jira. As response I get String with lots of fields, some of them are arrays. Request looks like:
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
Response string looks like:
{
"expand": "schema,names",
"total": 12,
"issues": [
{
"id": "32",
"key": "TEST-1",
"fields": {
"fixVersions": [
{
"description": "",
"releaseDate": "2017-04-02"
}
]
},
{
"id": "32",
"key": "TEST-2",
"fields": {
"fixVersions": [
{
"description": "",
"releaseDate": "2017-04-01"
}
]
}
]
}
Is it possible to convert this String into Map, where Object could be String or List of Map or something like this, without defining appropriate objects. As result, I'd like to have possibility to access description by: response.getIssues().get(0).getFields().getFixVersion().get(0).getDescription()
In such occasion, defining chain of specific objects looks too cumbersome.
You can create your own POJO classes which corresponds to the structure of the response JSON.
Based on the json that you have shared, you can have a class structure like this :
public class Response {
private String expand;
private String total;
private List<Issues> issues;
}
public class Issues {
private String id;
private String key;
private Map<String, List<FixVersions> fields;
}
public class FixVersions {
private String description;
private String releaseData;
}
Your GET call will change to the following :
ResponseEntity response = restTemplate.exchange(url,
HttpMethod.GET, entity, Response.class);
P.S. - All the fields in the POJO class must have their getters and
setters as well.
ANSWER given describes using LINQ to JSON and the JObject to convert from JSON to a workable object on the fly. Below is the completed code that takes me from my JSON to a workable object, followed by the original question.
'Parse string of JSON data into a JObject that can be accessed via VB.NET
Dim resultSet As JObject = JObject.Parse(responseBody)
'Data can be accessed as seen below
Dim cpu As String = CType(resultSet("KeyName"), String)
=========================================================================
I have a web app that will be making several API calls to a service called inContact (http://www.incontact.com/)
Each of the API calls will be receiving an HTTP response filled with JSON formatted in this way:
{
"resultSet": {
"_links": {
"self": "string",
"next": "string",
"previous": "string"
},
"businessUnitId": 0,
"lastPollTime": "2016-11-08T21:45:46.510Z",
"totalRecords": 0,
"agents": [
{
"agentId": 0,
"userName": "string",
"firstName": "string",
"middleName": "string",
"lastName": "string",
"emailAddress": "string",
"isActive": true,
"teamId": 0,
"teamName": "string",
"reportToId": 0,
"reportToName": "string",
"isSupervisor": true,
"lastLogin": "2016-11-08T21:45:46.510Z",
"lastUpdated": "2016-11-08T21:45:46.510Z",
"location": "string",
"custom1": "string",
"custom2": "string",
"custom3": "string",
"custom4": "string",
"custom5": "string",
"internalId": "string",
"profileId": 0,
"profileName": "string",
"timeZone": "string",
"country": "string",
"countryName": "string",
"state": "string",
"city": "string",
"chatRefusalTimeout": 0,
"phoneRefusalTimeout": 0,
"workItemRefusalTimeout": 0,
"defaultDialingPattern": 0,
"defaultDialingPatternName": "string",
"teamDefaultMaxChats": true,
"maxConcurrentChats": 0,
"notes": "string",
"createDate": "2016-11-08T21:45:46.510Z",
"inactiveDate": "2016-11-08T21:45:46.510Z",
"hireDate": "2016-11-08T21:45:46.510Z",
"terminationDate": "2016-11-08T21:45:46.510Z",
"rehireStatus": true,
"employmentType": 0,
"employmentTypeName": "Full-Time",
"referral": "string",
"atHome": true,
"hiringSource": "string",
"ntLoginName": "string",
"scheduleNotification": "5",
"federatedId": "string",
"sipUser": "string",
"useTeamMaxEmailInboxCount": true,
"maxEmailInboxCount": 0
}
]
}
}
I am deserializing the JSON with Newtonsoft. However, with each different call there will be different key/value pairs, such as this:
{
"resultSet": {
"businessUnitId": 0,
"lastPollTime": "2016-11-08T21:45:46.604Z",
"teams": [
{
"teamId": 0,
"teamName": "string",
"isActive": true,
"description": "string",
"notes": "string",
"lastUpdateTime": "2016-11-08T21:45:46.604Z",
"inViewEnabled": true,
"wfoEnabled": true,
"wfmEnabled": true,
"qmEnabled": true,
"maxConcurrentChats": 0,
"agentCount": 0,
"maxEmailInboxCount": true,
"inViewGamificationEnabled": true,
"inViewChatEnabled": true,
"inViewLMSEnabled": true,
"analyticsEnabled": true
}
],
"agents": [
{
"agentId": 0,
"firstName": "string",
"lastName": "string"
}
]
}
}
I currently am taking in the HTTP response and deserializing the JSON to create a workable .NET object. To do so this is my shortened code, omitting the HTTP request, assuming the request was successful:
If Not String.IsNullOrEmpty(responseBody) Then
' Success. Do something with the response.
'Declare object for holding the JSON from the API call for this call only (class does not fit other calls)
Dim resultSet As GetAgentsAPICall = New GetAgentsAPICall
'Deserialize JSON response into the new resultSet object
resultSet = JsonConvert.DeserializeObject(responseBody)
The issue is that I need a specific class for each API call, instead of just being able to take a string with JSON formatting and throw it into an object with properties matching the key/values. Below is the class I have that takes in just the above API call (the first one listed, longer in length):
Public Class GetAgentsAPICall
Public Property resultSet As Resultset
End Class
Public Class Resultset
Public Property _links As _Links
Public Property businessUnitId As Integer
Public Property lastPollTime As Date
Public Property totalRecords As Integer
Public Property agents() As Agent
End Class
Public Class _Links
Public Property self As String
Public Property _next As String
Public Property previous As String
End Class
Public Class Agent
Public Property agentId As Integer
Public Property userName As String
Public Property firstName As String
Public Property middleName As String
Public Property lastName As String
Public Property emailAddress As String
Public Property isActive As Boolean
Public Property teamId As Integer
Public Property teamName As String
Public Property reportToId As Integer
Public Property reportToName As String
Public Property isSupervisor As Boolean
Public Property lastLogin As Date
Public Property lastUpdated As Date
Public Property location As String
Public Property custom1 As String
Public Property custom2 As String
Public Property custom3 As String
Public Property custom4 As String
Public Property custom5 As String
Public Property internalId As String
Public Property profileId As Integer
Public Property profileName As String
Public Property timeZone As String
Public Property country As String
Public Property countryName As String
Public Property state As String
Public Property city As String
Public Property chatRefusalTimeout As Integer
Public Property phoneRefusalTimeout As Integer
Public Property workItemRefusalTimeout As Integer
Public Property defaultDialingPattern As Integer
Public Property defaultDialingPatternName As String
Public Property teamDefaultMaxChats As Boolean
Public Property maxConcurrentChats As Integer
Public Property notes As String
Public Property createDate As Date
Public Property inactiveDate As Date
Public Property hireDate As Date
Public Property terminationDate As Date
Public Property rehireStatus As Boolean
Public Property employmentType As Integer
Public Property employmentTypeName As String
Public Property referral As String
Public Property atHome As Boolean
Public Property hiringSource As String
Public Property ntLoginName As String
Public Property scheduleNotification As String
Public Property federatedId As String
Public Property sipUser As String
Public Property useTeamMaxEmailInboxCount As Boolean
Public Property maxEmailInboxCount As Integer
End Class
I'm trying to avoid having 20 or 30 similar lengthy classes prebuilt, and instead build a modifiable list or object on the fly. I will need to take the values and either store them in a database or modify them and use another API call to POST the values back. Does anyone have a best practice, or am I stuck with 20-30 huge class definitions?
Thanks for your time!
Parse it with a JObject, which can also be queried using LINQ (see Newtonsoft's LINQ to JSON API, which sits under the Newtonsoft.Json.Linq namespace):
JObject o = JObject.Parse(#"{
'CPU': 'Intel',
'Drives': [
'DVD read/writer',
'500 gigabyte hard drive'
]
}");
string cpu = (string)o["CPU"];
// Intel
string firstDrive = (string)o["Drives"][0];
// DVD read/writer
IList<string> allDrives = o["Drives"].Select(t => (string)t).ToList();
// DVD read/writer
// 500 gigabyte hard drive
The example is in C#, but you can find relevant VB.NET answers on StackOverflow (have a look at the answer here, for example).