[Gambas-user] gb.web.JSONCollection parse problem

jeff zacher adsicks at gmail.com
Thu Feb 21 20:54:16 CET 2019


Two valid JSON files will not parse properly with a call to

JSON.Decode(<json file contents>, True)

Consider this is valid JSON:
[
  {
   "name" : "Value",
   "another" : "Value"
  }
]

The above will decode as a Variant[] and not a JSONCollection.

Consider this other valid JSON:

{
  "name" : "value",
  "another" : {
        "nestedname" : "value"
  }
}

These will return as JSONCollections.

This is somewhat as expected, however there is no way to gracefully detect
what type of object has been decoded. Using Try blocks to determine by
trial and error which of the above forms of a JSON are present cannot be
good programming form. The TypeOf(<json file contents>) function gives a
gb.object type of object for both. This is very problematic when parsing
large files. What is the proper work around or how is this been properly
used in these cases  (what am I missing about this?)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190221/d27983cb/attachment.html>


More information about the User mailing list