I am getting a JSON response when hitting an API using an HTTP Request/Response. This part of the code is working fine. I am struggling to convert the response to a usable format.
Here is the JSON response in string:
{
"records":[
{
"id":"reciLUiZXJ8bs73JD",
"fields":{
"EstimatedDownTime":10,
"MaintenanceRequired":true,
"Reason":"Reason A",
"Reporting":"Tim",
"Notes":"Clean",
"TimeStamp":"2020-06-29T13:16:24.000Z"
},
"createdTime":"2020-06-29T13:16:24.000Z"
}
]
}
Current VB Code:
Dim json As String = myText
Dim jsonObject As Newtonsoft.Json.Linq.JObject = Newtonsoft.Json.Linq.JObject.Parse(json)
Dim jsonArray As JArray = jsonObject("fields")
For Each item As JObject In jsonArray
MsgBox(item.SelectToken("Notes").ToString)
Next
Any help getting the fields into separate variables for use else where in the program would be great! Thanks
Update, Here is the VB code i am using to try to deserialize json. However I am not getting any results from the deserializer.
myReq.Method = "GET"
myReq.ContentType = "application/json"
myReq.Headers.Add("Authorization: Bearer ************")
myResp = myReq.GetResponse
Dim myreader As New System.IO.StreamReader(myResp.GetResponseStream)
Dim myText As String
myText = myreader.ReadToEnd
MsgBox(myText)
Dim account As Fields = JsonConvert.DeserializeObject(Of Fields)(myText)
MsgBox(account.Notes)
Updated class list, Still not returning any values when calling:
Public Class Rootobject
Public Property records() As Record
End Class
Public Class Record
Public Property id As String
Public Property fields() As Fields
Public Property createdTime As DateTimeOffset
End Class
Public Class Fields
Public Property EstimatedDownTime As Integer
Public Property MaintenanceRequired As Boolean
Public Property Reason As String
Public Property Reporting As String
Public Property Notes As String
Public Property TimeStamp As Date
End Class
recordsclass object, which is an array of class objects. Thefieldsproperty is also a class object, that you already have. Add the missing parts (createdTimeis of typeDateTimeOffset, some utilities may convert it as string or DateTime, which is not correct).