toJSON: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
Tag: Manual revert
m (Text replacement - "↵|version1= 2.18↵↵|branch= dev↵" to " |version1= 2.18 ")
Line 3: Line 3:
|game1= arma3
|game1= arma3
|version1= 2.18
|version1= 2.18
|branch= dev


|gr1= Strings
|gr1= Strings

Revision as of 16:09, 8 October 2024

Hover & click on the images for description

Description

Description:
Serialise the passed data to JSON format.
Groups:
Strings

Syntax

Syntax:
toJSON data
Parameters:
data: can be one of:
  • HashMap: JSON object
  • Array: JSON array
  • Number: JSON number (float)
  • String: JSON string
  • Boolean: JSON bool (true/false, not 1/0)
  • nil: JSON null
    The nil value can only be passed as a member of Array/HashMap and cannot be passed directly as the command would simply not execute.
Return Value:
String - JSON result

Examples

Example 1:
private _result = toJSON ["this", "is", "an", "array"];
result:
["this","is","an","array"]
Example 2:
private _hashMap = createHashMap; _hashMap set ["bKey", true]; _hashMap set ["sKey", "Hello there"]; _hashMap set ["oKey", player]; _hashMap set ["nKey", 42]; _hashMap set ["hKey", ["key1", "key2", "yolo"] createHashMapFromArray ["General Kenobi", true, "Hello it's me"]]; toJSON _hashMap;

result:

{"bKey":true,"sKey":"Hello there","oKey":null,"nkey":42,hKey:{"key1":"General Kenobi","key2":true,"yolo":"Hello it's me"}}
Example 4:
private _jsonPlayer = toJSON player; // empty string - Object is not supported

Additional Information

See also:
fromJSON toString str

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