Coding environment: Xcode5.0 + cocos2d-x-2.2.2
The vast majority of current Cocos2d-x projects use lua scripting language. Today we will learn how to parse and encode json-format data in Lua scripts.
In Cocos2d-x 2.2.2, the engine provides us with a json4Lua module to help developers with Json parsing, in which the file is named as json. lua and json4Lua have two functions: Decoding and encoding. The method is very simple.
First let's take a look at the location of the json. lua file, open TestLua, file path: cocos2d-x-2.2.2/samples/Lua/TestLua
Take a look at the file directory:
For example, we can see the location of the json. lua file. When we need to use it, we can copy it to our own project directory. The following describes how to use it:
Json. lua has two functions that we need to use. The first one is called encode, which is used to encode a data type into json, and the second is decode, which is used to parse json into a table format. The usage is as follows:
Complex data