JsonText$ ( json )
Parameters
| json - JSON handle of kind JSON_STRING |
Description
|
Returns the text of a JSON String. The strict getter for text read back from a save file - player names, level identifiers, dialogue keys. The value comes back as strict UTF-8, byte-for-byte as it was stored: accents, kanji and emoji survive a save/load round trip exactly, with no normalization or trimming. The getters in this family never guess: JsonText accepts only JSON_STRING. It will not stringify a number or a Boolean for you - any other kind is a programming error that stops the program. Check JsonKind first on untrusted data; when you want a printable form of an arbitrary value, that job belongs to JsonStringify. Strings are created with CreateJsonString or parsed from quoted JSON text. For the full rules, see the Application Data language reference. Requires Extended mode. See also: CreateJsonString, JsonKind, JsonStringify, JsonBoolean, JsonInteger. |
Example
; JsonText Example ; ---------------- ; Requires Extended mode. q$=Chr(34) ; Double-quote character, for building JSON text ; Load a save-game and read the player's name back out save=ParseJson("{"+q+"player"+q+":"+q+"Aria"+q+","+q+"guild"+q+":"+q+"Night Owls"+q+"}") name_value=JsonObjectGet(save,"player") ; Check the kind before a strict getter - JsonText on a ; non-string kind is a programming error If JsonKind(name_value)=JSON_STRING Print "Welcome back, "+JsonText(name_value)+"!" Else Print "Save is corrupt: 'player' is not a string" EndIf ; Strings come back as strict UTF-8, exactly as stored guild_value=JsonObjectGet(save,"guild") Print "Guild: "+JsonText(guild_value) FreeJson guild_value FreeJson name_value FreeJson save Print "" Print "Press any key to close the example" WaitKey End
Index