ToJSON

From Multi Theft Auto: Wiki
Revision as of 20:04, 18 February 2013 by -ffs-Sniper (talk | contribs)
Jump to navigation Jump to search

Available client side in 1.2 and onwards This function converts a single value (preferably a Lua table) into a JSON encoded string. You can use this to store the data and then load it again using fromJSON.

Syntax

string toJSON ( var value )

Required Arguments

  • var: An argument of any type. Arguments that are elements will be stored as element IDs that are liable to change between sessions. As such, do not save elements across sessions as you will get unpredictable results.

Returns

Returns a JSON formatted string.

Example

This example shows how you can encode an array. The string json should equal "[ { "1": "dogs", "mouse": "food", "cat": "hungry", "birds": 4 } ]" after executed.

local json = toJSON ( { "dogs", cat = "hungry", mouse = "food", birds = 4 } )

Requirements

This template will be deleted.

See Also