As documented at https://www.json.org/json-en.html, the key
in a JSON object must be a string.
So, when parsing that string as JSON, you can't have that integer key. If you print error_string
after the call to JSON.parse
(as below), you'll see a meaningful error...
(Also, note that I've cleaned up the string creation syntax a bit...)
var dictionary_as_string = JSON.parse('{9:["Berry", 6]}')
print(dictionary_as_string.error_string)
To fix it, you'll need to make that key a string, like:
var dictionary_as_string = JSON.parse('{"9":["Berry", 6]}')
if typeof(dictionary_as_string.result) == TYPE_DICTIONARY:
print("dictionary")
else:
print("not dictionary")
That should result in the following output:
dictionary