Difference between revisions of "Json"

From GiderosMobile
Line 6: Line 6:
 
=== <translate>Description</translate> ===
 
=== <translate>Description</translate> ===
 
<translate>Provides Lua table serialization and deserialization to and from string in json format</translate>
 
<translate>Provides Lua table serialization and deserialization to and from string in json format</translate>
 +
 +
=== <translate>Examples</translate> ===
 +
'''Get user's geo:'''<br/>
 +
<source lang="lua">
 +
require('json')
 +
 +
local loader = UrlLoader.new("http://ip-api.com/json")
 +
 +
loader:addEventListener(Event.COMPLETE, function(event)
 +
local receivedTable=json.decode(event.data)
 +
print(receivedTable.countryCode)
 +
print(receivedTable.timezone)
 +
end)
 +
</source>
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|

Revision as of 16:28, 10 April 2019


Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2013.09

Description

Provides Lua table serialization and deserialization to and from string in json format

Examples

Get user's geo:

require('json')

local loader = UrlLoader.new("http://ip-api.com/json")

loader:addEventListener(Event.COMPLETE, function(event)
	local receivedTable=json.decode(event.data)
	print(receivedTable.countryCode)
	print(receivedTable.timezone)
end)

Methods

json.decode Returns Lua table from provided json encoded string
json.encode Returns encoded json string from provided Lua table

Events

Constants