XOJO.Data.ParseJSON Parse Error

Greetings,

Is this method with bugs or something ?

I`m trying to use the class that it is in Examples -> Communication -> Web Services -> AirTableArtGallery in Extensions you have a method called [quote]ConvertJSONToDictio[/quote]

And it has the following code :

[code]Function ConvertJSONToDictionary(Extends data As Xojo.Core.MemoryBlock) As Xojo.Core.Dictionary
Dim jsonData As Text
// Convert the content returned from the API from a MemoryBlock to Text.
jsonData = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(data)

// Parse the JSON result into a Dictionary
Dim jsonDict As Xojo.Core.Dictionary
jsonDict = Xojo.Data.ParseJSON(jsonData)

Return jsonDict
End Function[/code]

When it reaches to jsonDict = Xojo.Data.ParseJSON(jsonData) I get an TypeMismatchException with the reason [quote]Expected Object but got Auto[/quote]

If we look into the code and into the docs it says [quote]ParseJSON(json As Text) As Auto[/quote] and I`m supplying text in the end there so I have no idea why it is crashing .

Any ideas ?

Thanks

You have an invalid JSON string in regard to the target variable jsonDict, meaning your jsonData is not a JSON dictionary on the top level.

Maybe it is an array of dictionaries? What is the first character of jsonData, [ or { ?

[quote=356619:@Eli Ott]You have an invalid JSON string in regard to the target variable jsonDict, meaning your jsonData is not a JSON dictionary on the top level.

Maybe it is an array of dictionaries? What is the first character of jsonData, [ or { ?[/quote]

Well the data comes well formatted from Luna as API Output and it starts like :

[{"id":"1","FirstName":"A","LastName":"B","AccountStatus":"1","UpdatedOn":""},{"id":"2","FirstName":"C","LastName":"D","AccountStatus":"1","UpdatedOn":""}]

So I guess it is properly formatted.

Thanks

Got it so I guess in my case its an array, so I have to save the data in the array and then to loop trough and fetch the proper one.

Thanks .

This should work:

Dim jsonDict() As Auto = Xojo.Data.ParseJSON(jsonData)

I don’t know if this works though:

Dim jsonDict() As Xojo.Core.Dictionary = Xojo.Data.ParseJSON(jsonData)