Archived Forum Post

Index of archived forum posts

Question:

Problem creating complex JSON document

Apr 02 '16 at 15:29

I am trying to create a JSON string from a database using the Chilkat JSON object. I started with the example here: Create more Complex JSON Document. The JSON that I am trying create is a dictionary of arrays. If I modify the example code by removing the top 3 strings I get an object error. I am not sure the cause but I think it is something internal.

set json = Server.CreateObject("Chilkat_9_5_0.JsonObject")
Response.Write json.Version   <-- 9.5.0.56

' success = json.AddStringAt(-1,"Title","The Cuckoo's Calling")
' success = json.AddStringAt(-1,"Author","Robert Galbraith")
' success = json.AddStringAt(-1,"Genre","classic crime novel")   <-- allow any of these line and there is no error

success = json.AddObjectAt(-1,"Detail")
Set detail = json.ObjectAt(json.Size - 1)
success = detail.AddStringAt(-1,"Publisher","Little Brown")   <-- runtime error '800a01a8' Object required

Accepted Answer

Thanks! This was a bug -- if the JSON object is completely empty, and the very first item added is a sub-object, then the AddObjectAt returns false to indicate failure. (Internally, there is some initialization code that needed to be called but was not.)

This new build should fix it:

32-bit Download: http://www.chilkatsoft.com/download/preRelease/ChilkatAx-9.5.0-win32.zip

64-bit Download: http://www.chilkatsoft.com/download/preRelease/ChilkatAx-9.5.0-x64.zip