While parsing some third party JSONs with a list object named "data" I found a weird workaround which is probably a bug, but I'm using it as a feature.
When I add the word "data" (lowercase) to my custom Keywords in the IDE this program will work as intended, otherwise it will not.
Quick example:
Code: Select all
EnableExplicit
;# Struct
Structure sItemData
Val.i
EndStructure
Structure sItem
Id.i
List data.sItemData()
EndStructure
;# Global
Global NewList item.sItem()
Global *json_b = UTF8("W3siSWQiOjAsImRhdGEiOlt7IlZhbCI6NX0seyJWYWwiOjQ1fSx7IlZhbCI6NTl9LHsiVmFsIjo0OX0seyJWYWwiOjI0fV19LHsiSWQiOjEsImRhdGEiOlt7IlZhbCI6NDJ9LHsiVmFsIjo5M30seyJWYWwiOjkxfV19LHsiSWQiOjIsImRhdGEiOlt7IlZhbCI6ODB9LHsiVmFsIjoyOX0seyJWYWwiOjEyfV19LHsiSWQiOjMsImRhdGEiOlt7IlZhbCI6NDV9LHsiVmFsIjoyM31dfSx7IklkIjo0LCJkYXRhIjpbeyJWYWwiOjM4fSx7IlZhbCI6NTd9LHsiVmFsIjoxOH0seyJWYWwiOjYwfV19LHsiSWQiOjUsImRhdGEiOlt7IlZhbCI6OTd9LHsiVmFsIjoyMn0seyJWYWwiOjk0fSx7IlZhbCI6NTN9XX0seyJJZCI6NiwiZGF0YSI6W3siVmFsIjo1OX0seyJWYWwiOjY2fSx7IlZhbCI6Mzh9XX0seyJJZCI6NywiZGF0YSI6W3siVmFsIjowfSx7IlZhbCI6NzZ9LHsiVmFsIjo1OH1dfSx7IklkIjo4LCJkYXRhIjpbeyJWYWwiOjF9LHsiVmFsIjoyMX0seyJWYWwiOjYwfV19LHsiSWQiOjksImRhdGEiOlt7IlZhbCI6NTh9LHsiVmFsIjo3fV19LHsiSWQiOjEwLCJkYXRhIjpbeyJWYWwiOjM2fSx7IlZhbCI6NDl9LHsiVmFsIjo2NH0seyJWYWwiOjk0fSx7IlZhbCI6Mjh9XX1d")
Global.s json$ = PeekS(*json_b, MemorySize(*json_b), #PB_UTF8)
Global *json_e = AllocateMemory(MemorySize(*json_b)) : Base64Decoder(json$, *json_e, MemorySize(*json_b))
Global.s json_d$ = PeekS(*json_e, -1, #PB_UTF8)
Global.i obj = ParseJSON(#PB_Any, json_d$)
;# Following code will always be negative if "data" has not been set as a custom keyword in the IDE Settings (Editor > Coloring > Custom keywords)
If obj
ExtractJSONList(JSONValue(obj), item())
ForEach item()
If ListSize(item()\Data())
Debug Str(item()\Id) + " item()\data() List found, size: " + ListSize(item()\data())
Else
Debug Str(item()\Id) + " item()\data() List NOT found"
EndIf
Next item()
Debug Chr(10) + ComposeJSON(obj, #PB_JSON_PrettyPrint)
EndIf
DisableExplicit
Results:
If data keyword has been added.
If no data keyword has been added.