toJSON: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) No edit summary Tag: Manual revert |
(Small page overhaul) |
||
(One intermediate revision by one other user not shown) | |||
Line 3: | Line 3: | ||
|game1= arma3 | |game1= arma3 | ||
|version1= 2.18 | |version1= 2.18 | ||
|gr1= Strings | |gr1= Strings | ||
|descr= | |descr= Converts data to {{Link|https://en.wikipedia.org/wiki/JSON|JSON}}. | ||
|s1= [[toJSON]] data | |s1= [[toJSON]] data | ||
|p1= data | |p1= data - Only certain [[Data Types]] are supported: | ||
* [[Boolean]] - serialized as JSON boolean | |||
* [[ | * [[Number]] - serialized as JSON number (floating-point) | ||
* [[Number]] | * [[String]] - serialized as JSON string | ||
* [[String]] | * [[Array]] - Serialized as JSON array. Unsupported elements (e.g. [[Object]]s) are converted to JSON null. | ||
* [[ | * [[HashMap]] - Serialized as JSON object. Only [[String]] keys are supported, other keys are ignored. Unsupported values (e.g. [[Object]]s) are converted to JSON null. | ||
* [[nil]] | * [[nil]] - serialized as JSON null {{Feature|important|The [[nil]] value can only be passed as a member of an [[Array]] or [[HashMap]]. It cannot be passed directly as the command would simply not execute.}} | ||
|r1= [[String]] - JSON | |r1= [[String]] - JSON string | ||
|x1= <sqf> | |x1= <sqf> | ||
private _result = toJSON ["this", "is", "an", "array"]; | private _result = toJSON ["this", "is", "an", "array"]; | ||
</sqf> | </sqf> | ||
Result: | |||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
["this","is","an","array"] | ["this","is","an","array"] | ||
Line 39: | Line 37: | ||
toJSON _hashMap; | toJSON _hashMap; | ||
</sqf> | </sqf> | ||
Result (formatted for readability): | |||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
{"bKey":true,"sKey":"Hello there","oKey":null,"nkey":42,hKey:{"key1":"General Kenobi","key2":true,"yolo":"Hello it's me"}} | { | ||
"bKey": true, | |||
"sKey": "Hello there", | |||
"oKey": null, | |||
"nkey": 42, | |||
"hKey": { | |||
"key1": "General Kenobi", | |||
"key2": true, | |||
"yolo": "Hello it's me" | |||
} | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 17:34, 4 November 2024
Description
Syntax
- Syntax:
- toJSON data
- Parameters:
- data - Only certain Data Types are supported:
- Boolean - serialized as JSON boolean
- Number - serialized as JSON number (floating-point)
- String - serialized as JSON string
- Array - Serialized as JSON array. Unsupported elements (e.g. Objects) are converted to JSON null.
- HashMap - Serialized as JSON object. Only String keys are supported, other keys are ignored. Unsupported values (e.g. Objects) are converted to JSON null.
- nil - serialized as JSON null
- Return Value:
- String - JSON string
Examples
- Example 1:
-
Result:
["this","is","an","array"]
- Example 2:
Result (formatted for readability):
{ "bKey": true, "sKey": "Hello there", "oKey": null, "nkey": 42, "hKey": { "key1": "General Kenobi", "key2": true, "yolo": "Hello it's me" } }
- Example 4:
Additional Information
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note