FromJSON: Difference between revisions
Jump to navigation
Jump to search
Fernando187 (talk | contribs) (Remove obsolete Requirements section) |
Fernando187 (talk | contribs) m (Fix examples header) |
||
Line 16: | Line 16: | ||
'''Note:''' Indices of a JSON object such as "1": "cat" are being returned as [[string]], not as [[int]]eger. | '''Note:''' Indices of a JSON object such as "1": "cat" are being returned as [[string]], not as [[int]]eger. | ||
== | ==Examples== | ||
This makes data equal: ''{ ["1"] = "cat", ["2"] = "mouse", ["3"] = 5, ["4"] = null, ["cat"] = 5, ["mouse"] =1 }'' | This makes data equal: ''{ ["1"] = "cat", ["2"] = "mouse", ["3"] = 5, ["4"] = null, ["cat"] = 5, ["mouse"] =1 }'' | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 22: | Line 22: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local name, weapon, ammo = fromJSON("[\"Desert Eagle\", 24, 147]") | local name, weapon, ammo = fromJSON("[\"Desert Eagle\", 24, 147]") |
Revision as of 13:36, 8 June 2025
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.
Examples
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 } ]' )
local name, weapon, ammo = fromJSON("[\"Desert Eagle\", 24, 147]")
See Also
- getMaxPlayers
- getServerConfigSetting
- getServerHttpPort
- getServerName
- getServerPassword
- getServerPort
- isGlitchEnabled
- setGlitchEnabled
- setMaxPlayers
- setServerConfigSetting
- setServerPassword
- shutdown