JsonInteger:Long ( json )
Parameters
| json - JSON handle of kind JSON_INTEGER |
Description
|
Returns the value of a JSON integer as a signed 64-bit Long. The strict getter for whole numbers read back from a save file - gold totals, lifetime scores, timestamps. The full Long range round-trips exactly, so a veteran's score beyond the 32-bit limit comes back untouched. The getters in this family never guess: JsonInteger accepts only JSON_INTEGER. It will not truncate a JSON_NUMBER Double, parse a numeric string or substitute a default - any other kind is a programming error that stops the program. Check JsonKind first on untrusted data. Note the asymmetry with JsonNumber: that getter does accept an integer (converting Long to Double), but JsonInteger never accepts a number. Integers are created with CreateJsonInteger or parsed from tokens without a decimal point or exponent. For the full rules, see the Application Data language reference. Requires Extended mode. See also: CreateJsonInteger, JsonNumber, JsonKind, JsonBoolean, JsonText. |
Example
; JsonInteger Example ; ------------------- ; Requires Extended mode. q$=Chr(34) ; Double-quote character, for building JSON text ; A veteran's save-game: the total score needs 64 bits save=ParseJson("{"+q+"player"+q+":"+q+"Aria"+q+","+q+"total_score"+q+":9000000000}") score=JsonObjectGet(save,"total_score") ; Check the kind before a strict getter - JsonInteger on a ; non-integer kind is a programming error If JsonKind(score)=JSON_INTEGER ; JsonInteger returns a signed 64-bit Long Print "total_score = "+JsonInteger(score) Print "That is well past the 32-bit limit of 2147483647." Else Print "Save is corrupt: 'total_score' is not an integer" EndIf FreeJson score FreeJson save Print "" Print "Press any key to close the example" WaitKey End
Index