Cocos2d-x tutorial (22)-json parsing in lua

Source: Internet
Author: User

 

 

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

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.