FromJSON: Difference between revisions
Jump to navigation
Jump to search
Cazomino05 (talk | contribs) No edit summary |
Fernando187 (talk | contribs) (Remove obsolete Requirements section) |
||
(9 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | {{Server client function}} | ||
This function parses a [[JSON]] formatted string into variables. You can use [[toJSON]] to encode variables into a JSON string that can be read by this function. | This function parses a [[JSON]] formatted string into variables. You can use [[toJSON]] to encode variables into a JSON string that can be read by this function. | ||
Line 39: | Line 26: | ||
local name, weapon, ammo = fromJSON("[\"Desert Eagle\", 24, 147]") | local name, weapon, ammo = fromJSON("[\"Desert Eagle\", 24, 147]") | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Server_functions}} | {{Server_functions}} |
Latest revision as of 15:32, 7 November 2024
This function parses a JSON formatted string into variables. You can use toJSON to encode variables into a JSON string that can be read by this function.
Syntax
var fromJSON ( string json )
Required Arguments
- json: A JSON formatted string
Returns
Returns variables read from the JSON string.
Note: Indices of a JSON object such as "1": "cat" are being returned as string, not as integer.
Example
This makes data equal: { ["1"] = "cat", ["2"] = "mouse", ["3"] = 5, ["4"] = null, ["cat"] = 5, ["mouse"] =1 }
local data = fromJSON ( '[ { "1": "cat", "2": "mouse", "3": 5, "4": null, "cat":5, "mouse":1 } ]' )
Example 2
local name, weapon, ammo = fromJSON("[\"Desert Eagle\", 24, 147]")
See Also
- getMaxPlayers
- getServerConfigSetting
- getServerHttpPort
- getServerName
- getServerPassword
- getServerPort
- isGlitchEnabled
- setGlitchEnabled
- setMaxPlayers
- setServerConfigSetting
- setServerPassword
- shutdown