CreateJsonString ( value$ )
Parameters
| value$ - the text to store, as strict UTF-8 |
Description
|
Creates an owned JSON String from strict UTF-8 text. JSON strings hold strict UTF-8, so an international player name - accents, kanji, emoji - survives saving and loading without mangling. The text is stored and later serialized exactly; no normalization, trimming or case folding happens behind your back. The text must be valid UTF-8: since Extended-mode Strings normally are, this only bites when you build strings from raw bytes yourself - invalid UTF-8 here is a programming error, not a quiet fix-up. A single string is limited to 16 MiB. If you have legacy bytes in another encoding, run them through DecodeText first. Read the value back with JsonText; its kind is JSON_STRING under JsonKind. The returned handle is owned by you: release it with FreeJson. Container setters copy their input, so the usual pattern is create, set, free. For the full rules, see the Application Data language reference. Requires Extended mode. See also: JsonText, JsonObjectSet, DecodeText, CreateJsonObject, FreeJson. |
Example
; CreateJsonString Example ; ------------------------ ; Requires Extended mode. ; JSON strings hold strict UTF-8 text, so international player ; names survive saving without mangling player_name=CreateJsonString("Café 世界") Print "Kind is JSON_STRING: "+(JsonKind(player_name)=JSON_STRING) Print "JsonText returns: "+JsonText(player_name) Print "" ; Store it in a save-game record to see it serialized save=CreateJsonObject() JsonObjectSet save,"player",player_name Print "In a save file: "+JsonStringify(save,0) FreeJson save FreeJson player_name Print "" Print "Press any key to close the example" WaitKey End
Index