FromJSON: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 4: Line 4:
Available client side in 1.2 and onwards.
Available client side in 1.2 and onwards.
}}
}}
 
{{MessageBox|
  bordercolorhex = FFADAD |
  bordertype = |
  bgcolorhex = F9F9F9 |
  image = File:Dialog-warning.png |
  title = Warning: |
  message = There is a known bug with this described in the mantis issue 6613 |
  subtext = http://bugs.mtasa.com/view.php?id=6613 |
}}
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.



Revision as of 00:33, 19 March 2014

Available client side in 1.2 and onwards.

Dialog-warning.png Warning: There is a known bug with this described in the mantis issue 6613

http://bugs.mtasa.com/view.php?id=6613

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]")

Requirements

This template will be deleted.

See Also