CreateJsonInteger ( value:Long )
Parameters
| value - the number to store, a signed 64-bit Long |
Description
|
Creates an owned signed 64-bit JSON integer. JSON integers are full Longs, so a lifetime score, a coin total or a Millisecs-style timestamp can grow far past the 32-bit Int limit of 2147483647 and still round-trip exactly. The value serializes as a plain base-10 integer with no decimal point, and parsing it back gives the identical Long. Integers are a distinct kind (JSON_INTEGER) from floating-point numbers (JSON_NUMBER) - JsonEqual treats integer 1 and number 1.0 as different, and the strict getter JsonInteger only accepts JSON_INTEGER. JsonNumber will also read an integer, converting Long to Double (which can round above 2^53). 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: JsonInteger, CreateJsonNumber, JsonKind, JsonObjectSet, FreeJson. |
Example
; CreateJsonInteger Example ; ------------------------- ; Requires Extended mode. ; JSON integers are signed 64-bit Longs, so a total score can ; grow far beyond the 32-bit Int limit of 2147483647 total_score=CreateJsonInteger(9000000000L) Print "Kind is JSON_INTEGER: "+(JsonKind(total_score)=JSON_INTEGER) Print "JsonInteger returns: "+JsonInteger(total_score) Print "" ; Store it in a save-game record to see it serialized exactly save=CreateJsonObject() JsonObjectSet save,"total_score",total_score Print "In a save file: "+JsonStringify(save,0) FreeJson save FreeJson total_score Print "" Print "Press any key to close the example" WaitKey End
Index