FromJSON

From Multi Theft Auto: Wiki
Revision as of 20:39, 15 March 2012 by -ffs-Sniper (talk | contribs)
Jump to navigation Jump to search

Dialog-information.png This article needs checking.

Reason(s): Example 1 does not work. FromJSON is not compatible with JSON objects such as "cat:5, mouse:1". You might only use JSON arrays instead or move the JSON formatting to PHP ---ffs-Sniper 20:39, 15 March 2012 (UTC)

Available client side in 1.2 and onwards 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.

Example

This should make data equal: {1="cat", 2="mouse", 3=5, 4=null, 5={cat=5, mouse=1}} (untested)

local data = fromJSON("[\"cat\", \"mouse\", 5, null, {cat:5, mouse:1}]")

Example 2

local name, weapon, ammo = fromJSON("[\"Desert Eagle\", 24, 147]")

Requirements

This template will be deleted.

See Also