Hello, I’m new to Xojo, though I’ve been programming in VBA, VB6, VB.Net and C# for 20+ years. I am used to using SOAP webservices but have never used JSON.
For a new project I am working on, I have set up a webservice which uses NewtonSoft to create JSON. The output looks like this in Firefox:
{“array”:[{“ID”:“4”,“CodePurpose”:“OrgType”,“Description”:“Charity”},{“ID”:“1”,“CodePurpose”:“OrgType”,“Description”:“Client”},{“ID”:“2”,“CodePurpose”:“OrgType”,“Description”:“Funder”},{“ID”:“5”,“CodePurpose”:“OrgType”,“Description”:“Housing Association”},{“ID”:“6”,“CodePurpose”:“OrgType”,“Description”:“Landlord”},{“ID”:“3”,“CodePurpose”:“OrgType”,“Description”:“Supplier”},{“ID”:“9”,“CodePurpose”:“PersonType”,“Description”:“Client”},{“ID”:“12”,“CodePurpose”:“PersonType”,“Description”:“Examiner”},{“ID”:“8”,“CodePurpose”:“PersonType”,“Description”:“Manager”},{“ID”:“7”,“CodePurpose”:“PersonType”,“Description”:“Proprietor”},{“ID”:“10”,“CodePurpose”:“PersonType”,“Description”:“Teacher”},{“ID”:“11”,“CodePurpose”:“PersonType”,“Description”:“Trainer”}]}
As I understand it, this is a tagged array with a single dictionary inside it.
I have a Xojo desktop app with a Xojo.Net.HTTPSocket, and a PageReceived event on my main form.
My code on that form is (at the moment):
var jsonData As Text = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(Content)
var jsonArray() As Variant
jsonArray = Xojo.Data.ParseJSON(jsonData)
I am getting a JSON error “Top level JSON objects can only be maps or arrays.”
I have tried the other three methods suggested on the Xojo ParseJSON help page but with no better results.
Can anyone help with this issue? I am happy to share the URL of the webservice if necessary - the data is only test data at the moment.
Thanks
John