HI all,
Please could you help point out where I’m going wrong with my JSON response? My error is on assigning my parsed json data to the templates variable and the debugger says: ‘Expected array of Auto but got class Xojo.Core.Dictionary’ which I can understand, but changing my templates variable to dictionary doesn’t help. Is it because my json data contains an array of json objects?
Sub PageReceived(URL as Text, HTTPStatus as Integer, Content as xojo.Core.MemoryBlock)
Dim jsonData as Text
// Convert memorblock data into text
jsonData = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(content)
// Parse json data into array
Dim templates() As Auto
templates = Xojo.Data.ParseJSON(jsonData)
// For each post in the array, add the title to the listbox
For Each subDict As Xojo.Core.Dictionary in templates
Dim t As String = subDict.Value("templateId")
Listbox1.AddRow(t)
Next
End Sub
The JSON response I’m getting from the server is:
{
"templates":[
{
"templateId":"IDCR Allergies List.v0",
"createdOn":"2017-11-17T15:01:42.253Z"
},
{
"templateId":"IDCR - Laboratory Order.v0",
"createdOn":"2017-11-17T15:01:42.368Z"
},
{
"templateId":"IDCR - Laboratory Test Report.v0",
"createdOn":"2017-11-17T15:01:42.293Z"
},
{
"templateId":"IDCR Problem List.v1",
"createdOn":"2017-11-17T15:01:42.221Z"
},
{
"templateId":"IDCR Procedures List.v0",
"createdOn":"2017-11-17T15:01:42.562Z"
},
{
"templateId":"Vital Signs Encounter (Composition)",
"createdOn":"2017-11-17T15:01:42.477Z"
}
]
}
Thank you for any help and hints.