I need to duplicate what I can do in Xojo in VB.Net. THis will be for custom Code on Kodak Rules Based Automation that uses embedded VB.Net. How do I make VB.net code do the same thing that the Xojo code I show below does. As much as I have searched for solutions, nothing I try in VB does anything but give me errors trying to use a dictionary to retrieve the values. I've installed the Newtonsoft DLL in Prinergy so the various methods for "deserializing" the JSON I've found don't give me compile errors but getting beyond that to duplicate what I can do in Xojo is escaping me.
I need to Parse a JSON response from a REST API to determune if a Name has a specific status. I have searched for examples here and have tried numerous attempts to adapt what I have found for VB.Net, but I cannot get any code past the following to work:
Dim jsonstring As String = responseFromServer
Dim Worksteps As Dictionary(Of String, String) = JsonConvert.DeserializeObject(Of Dictionary(Of String, String))(jsonstring)
Here is a sample of the JSON that is returned from the VB.Net code that is working:
{
"error": null,
"worksteps": [
{
"id": "_210504_125916572_029875",
"name": "Sheet_1 4/4",
"job": {
"id": "060671-21",
"name": "2021 Laramie High School"
},
"status": "COMPLETED",
"amountPlanned": 544,
"wastePlanned": 60,
"amountProduced": 169,
"wasteProduced": 69,
"deviceId": "114",
"types": [
"ConventionalPrinting"
],
"sequenceType": "SheetfedPrinting",
"start": "2021-05-05T09:46:06-05:00",
"end": "2021-05-05T09:48:38-05:00",
"startPlanned": "2021-05-05T07:52:22-05:00",
"endPlanned": null,
"setuptimePlanned": 0,
"prodtimePlanned": 0,
"actualTimes": [
{
"timeTypeGroupName": "Production time",
"timeTypeName": "Execution time",
"duration": 33
},
{
"timeTypeGroupName": "Production time",
"timeTypeName": "Setup time",
"duration": 79
},
{
"timeTypeGroupName": "Auxiliary time",
"timeTypeName": "Auxiliary time",
"duration": 40
},
{
"timeTypeGroupName": "",
"timeTypeName": "",
"duration": 0
}
]
},
{
"id": "_210506_072306983_020035",
"name": "Sheet_2 4/4",
"job": {
"id": "060671-21",
"name": "2021 Laramie High School"
},
"status": "WAITING",
"amountPlanned": 0,
"wastePlanned": 0,
"amountProduced": 0,
"wasteProduced": 0,
"deviceId": "XL106_Pool",
"types": [
"ConventionalPrinting"
],
"sequenceType": "SheetfedPrinting",
"start": null,
"end": null,
"startPlanned": null,
"endPlanned": null,
"setuptimePlanned": 0,
"prodtimePlanned": 0,
"actualTimes": null
}
]
}
And here is working Xojo 2021r1.1 Code that does what I am attempting to accomplish in VB.Net:
Public Function ParseWorkstepsJSON(jsontext As String, sheetname As String) As Boolean
' Parse the JSON and Put the resulting Worksteps Array into a new Dictionary
Var jsonDict As Dictionary = ParseJSON(jsontext)
Var JobWorksteps() As Object = jsonDict.Lookup("worksteps", New Dictionary())
' Loop through each Action Dictionary in the Actions Dictionary and Process the data within into an Array of values
Worksteps.ResizeTo(JobWorksteps.LastIndex,1)
For idx As Integer = 0 to JobWorksteps.LastIndex
Var wkstp As Dictionary = Dictionary(JobWorksteps(idx))
' Process the data in the Action in the order we want to store it in the array
' WorkStep Name
If Not (wkstp.Value("name") = Nil) Then
Worksteps(idx,0) = wkstp.Value("name")
Else
Worksteps(idx,0) = ""
End If
' WorkStep Status
If Not (wkstp.Value("status") = Nil) Then
Worksteps(idx,1) = wkstp.Value("status")
Else
Worksteps(idx,1) = ""
End If
Next
' Determine whether "Sheet_1" staus = "COMPLETED"
Var b As Boolean
Var s As String
For idx As Integer = 0 To Worksteps.LastIndex
s = Worksteps(idx,0).NthField(" ",1)
If s = sheetname Then
If Worksteps(idx,1) = "COMPLETED" Then
Return True
End If
End If
Next
Return False
End Function
I do not have to put the JSON into a Dictionary in VB.Net like in Xojo, which was what I was attempting, if there is a different way to accomplish the task of determining whether a specific "name" value in the JSON has a corresponding "status" with a Value of "COMPLETED"