How to store a JSON string in a DataSection?
Posted: Thu May 30, 2019 10:59 pm
JSON strings include {:[", etc, so how can that be encapsulated in a DataSection?
http://www.purebasic.com
http://forums.purebasic.com/english/
Code: Select all
EnableExplicit
Structure TEST_STRUCT
DecimalPlaces.i
WindowRect.RECT
EndStructure
Define.s json_raw
Define.s json_unescaped
Define.TEST_STRUCT struct
; obtain the raw escaped data.
Restore json_data
Read.s json_raw
json_unescaped = UnescapeString(json_raw, #PB_String_EscapeXML) ; unescape the string data
Define.i json = ParseJSON(#PB_Any, json_unescaped) ; parse the unescaped string
If IsJSON( json ) ; did we get a valid json?
ExtractJSONStructure(JSONValue(json), @struct, TEST_STRUCT) ; load up the data onto the structure
FreeJSON( json ) ; get rid of the jeeey, son.
EndIf
;Show me what you've got!
Debug json_raw
Debug "-------"
Debug json_unescaped
Debug "-------"
Debug "Decimal places: " + struct\DecimalPlaces
Debug "Rect Left: " + struct\WindowRect\left
Debug "Rect Bottom: " + struct\WindowRect\bottom
Debug "Rect Top: " + struct\WindowRect\top
Debug "Rect Right: " + struct\WindowRect\right
DataSection
json_data:
Data.s "{"WindowRect":{"left":12,"bottom":34,"top":56,"right":78},"DecimalPlaces":1234}"
Code: Select all
Debug EscapeString( GetClipboardText(), #PB_String_EscapeXML)
... great idea, thank you.You could store the JSON string in a file and use IncludeBinary "D:\file" in the DataSection.