I will admit to being a total novice when it comes to JSON and in my first attempt to parse data from a HTTP GET from a production system I have encountered a TypeMismatchException using code from the example project “JSON Example.xojo_binary_project” combined with the “HTTP Example.xojo_binary_project”
I can successfully retrieve the JSON data from the server:
{"linkedResource":[],"jobletID":null,"internalJobID":"f60cb80580b94b1daf8c3912428e8465","id":null,"propertySet":[],"properties":{"planDescriptor_name":"Perfect Bind - Xerox","custom_Signaturename":null,"custom_Final":null,"job_activeWorkCells":"","job_customerOrderId":"29154","job_submittedTime":"2016-12-28T10:32:53-06:00","job_rootJobletId":"452776","custom_Locationid":null,"c_PressTicketID":null,"job_hasLateTask":null,"job_dueDate":"2017-01-20T10:31:00-06:00","job_inputConfiguration":null,"job_customerJobName":null,"job_completedTime":"2016-12-30T07:07:44-06:00","job_rootJobletStatus":"ready for next processor","c_SkipPersonalization":null,"job_batchName":null,"custom_Trimsize":null,"custom_Signatureid":null,"job_nextDropDeadDate":null,"job_priority":"50","planDescriptor_id":"SaPerfectBindCover","job_condition":"OK","job_hasRework":"false","job_customerOrgName":null,"job_orderQuantity":"1","job_status":"Completed","c_CoverType":null,"job_name":"029154-16.CM_DCE.1A.PDF","job_dueDay":"5","job_id":"f60cb80580b94b1daf8c3912428e8465","custom_Booid":null,"job_reworkRequested":"false","job_modifiedTime":"2016-12-30T07:07:44-06:00"},"link":[{"type":null,"desc":null,"rel":"self","href":"http://clkswjmhpctr.clkmfg.jostens.com/rest/jobs/f60cb80580b94b1daf8c3912428e8465","op":null},{"type":null,"desc":null,"rel":"delete","href":"http://clkswjmhpctr.clkmfg.jostens.com/rest/jobs/f60cb80580b94b1daf8c3912428e8465","op":null},{"type":null,"desc":null,"rel":"printableticket","href":"http://clkswjmhpctr.clkmfg.jostens.com/rest/jobs/f60cb80580b94b1daf8c3912428e8465/printableticket/pdf","op":null}],"expand":null}
Using Kem T’s code for “Making pretty JSON” I can process the raw text to look like this:
{
"linkedResource":[],
"jobletID":null,
"internalJobID":"f60cb80580b94b1daf8c3912428e8465",
"id":null,
"propertySet":[],
"properties":{
"planDescriptor_name":"Perfect Bind - Xerox",
"custom_Signaturename":null,
"custom_Final":null,
"job_activeWorkCells":"",
"job_customerOrderId":"29154",
"job_submittedTime":"2016-12-28T10:32:53-06:00",
"job_rootJobletId":"452776",
"custom_Locationid":null,
"c_PressTicketID":null,
"job_hasLateTask":null,
"job_dueDate":"2017-01-20T10:31:00-06:00",
"job_inputConfiguration":null,
"job_customerJobName":null,
"job_completedTime":"2016-12-30T07:07:44-06:00",
"job_rootJobletStatus":"ready for next processor",
"c_SkipPersonalization":null,
"job_batchName":null,
"custom_Trimsize":null,
"custom_Signatureid":null,
"job_nextDropDeadDate":null,
"job_priority":"50",
"planDescriptor_id":"SaPerfectBindCover",
"job_condition":"OK",
"job_hasRework":"false",
"job_customerOrgName":null,
"job_orderQuantity":"1",
"job_status":"Completed",
"c_CoverType":null,
"job_name":"029154-16.CM_DCE.1A.PDF",
"job_dueDay":"5",
"job_id":"f60cb80580b94b1daf8c3912428e8465",
"custom_Booid":null,
"job_reworkRequested":"false",
"job_modifiedTime":"2016-12-30T07:07:44-06:00"
},
"link":[
{
"type":null,
"desc":null,
"rel":"self",
"href":"http://clkswjmhpctr.clkmfg.jostens.com/rest/jobs/f60cb80580b94b1daf8c3912428e8465",
"op":null
},
{
"type":null,
"desc":null,
"rel":"delete",
"href":"http://clkswjmhpctr.clkmfg.jostens.com/rest/jobs/f60cb80580b94b1daf8c3912428e8465",
"op":null
},
{
"type":null,
"desc":null,
"rel":"printableticket",
"href":"http://clkswjmhpctr.clkmfg.jostens.com/rest/jobs/f60cb80580b94b1daf8c3912428e8465/printableticket/pdf",
"op":null
}
],
"expand":null
}
When I attempt to parse this data regardless of whether I’ve made it pretty I get the TypeMismatchException at the link array. “An exception of class TypeMismatchException was not handled. The Application Must be shut down.”
The code I’m using to parse the JSON is directly from the “JSON Example.xojo_binary_project”
For i As Integer = 0 To obj.Count-1
If obj.IsArray Then
JSONList.AddRow(CStr(i))
JSONList.cell(JSONList.LastIndex, 1) = obj(i)
Else
Dim key As String = obj.Name(i)
If obj.value(key) IsA JSONItem Then
JSONList.AddFolder(key)
JSONList.RowTag(JSONList.LastIndex) = obj.Value(key)
JSONList.Expanded(JSONList.LastIndex) = True
Else
JSONList.AddRow(key)
JSONList.Cell(JSONList.LastIndex, 1) = obj.Value(key)
End If
End If
Next i
The exception occurs at the line: JSONList.cell(JSONList.LastIndex, 1) = obj(i)
The why of it is escaping me, not to mention if there is a work around. I’ve attempted to parse the JSON item into a Dictionary with the same results. It seems no matter what I query from this service parsing fails. Anybody have any advice?