FromJSON: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(The bug that existed in MTA 1.3.6 is no longer relevant so i removed that warning message.)
(3 intermediate revisions by 3 users not shown)
Line 3: Line 3:
{{New feature/item|3.0140|1.2||
{{New feature/item|3.0140|1.2||
This function is available client-side in 1.2 and onwards.
This function is available client-side in 1.2 and onwards.
}}
{{MessageBox|
  bordercolorhex = FFADAD |
  bordertype = |
  bgcolorhex = F9F9F9 |
  image = File:Dialog-warning.png |
  title = Warning: |
  message = Fixed in 1.3.6. There is a known bug with this function described in the Mantis issue #6613. |
  subtext = http://bugs.mtasa.com/view.php?id=6613 |
}}
}}



Revision as of 01:08, 1 July 2017

This function is 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.

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

Minimum server version 1.0
Minimum client version 1.1.1-9.03316

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.0" client="1.1.1-9.03316" />

See Also