Problem parsing json array
Error Expected Object but got Auto
Dim jsonDict As Xojo.Core.Dictionary
jsonDict = Xojo.Data.ParseJSON(jsonData)
[{"PK_File":"1","EK_MediaType":"24","FK_MediaSubType":"","FK_FileFormat":"","FK_FileGroup":"","DateAdded":"2015-12-20 16:20:25","Path":"\\/home\\/public\\/data","Filename":"tts","Missing":"0","IsDirectory":"1","EK_Users_Private":"","EK_Device":"","ModificationDate":"2017-03-26 17:29:04","AttrCount":"0","AttrDate":"0-00-00 00:00:00","DateLastViewed":"","IsNew":"1","Ignore":"0","INode":"2654212","MD5":"","Source":"F","psc_id":"","psc_batch":"","psc_user":"","psc_frozen":"0","psc_mod":"2017-03-26 17:31:48","psc_restrict":""}]
Norman_P
(Norman P)
March 27, 2017, 12:45am
2
According to http://developer.xojo.com/xojo-data$ParseJSON
Xojo.Data.ParseJSON(jsonData) returns an Auto not a dictionary
Dim json As Auto
json = Xojo.Data.ParseJSON(jsonData)
dim jsonArray() as Auto
// see if this is an array of json items
try
jsonArray() = json
// do something with each element of the array
catch
// it wasnt an array just a dict
end try
JSON can be a dictionary or an array. I guess this is why the new framework returns an auto.
[code]Try
Dim jValue as auto = Xojo.Data.ParseJSON(jsonData)
if not jValue isa Xojo.Core.Dictionary then return // Bail if it’s not a dictionary.
Dim jsonDict As Xojo.Core.Dictionary = Xojo.Core.Dictionary( jValue )
// ~ Do dictionary processing here
catch err as JSONException
// — Unable to process the JSON data.
End try
[/code]
I’ve not tested the above code and I haven’t done much with the new framework yet.
That code would be fine if the top level of the json represented an object, but it does not, it’s an array so parse is returning Auto(), not a Dictionary.