cocos2d-x lua table与json的转换

version: cocos2d-x 3.6


1.引入json库

require("src/cocos/cocos2d/json")


2.使用json

function testJson()
local beginTime = os.time() local testTable = {}
-- [
-- {
-- "UserId": "1234567890",
-- "Name": "test1",
-- "Icon": "www.google.com"
-- },
-- {
-- "UserId": "1234567890",
-- "Name": "test2",
-- "Icon": "www.google.com"
-- }
-- ]
for i = 1, 100 do
table.insert(testTable, {["UserId"]="123", ["Name"]="test1", ["Icon"]="www.google.com"})
end -- encode
local jsonData = json.encode(allUserData)
print("user data json:\n" .. jsonData) -- decode
testTable = json.decode(jsonData) local endTime = os.time()
print("test time: " .. tostring(endTime - beginTime))
end

cocos2d-x lua table与json的转换的更多相关文章

  1. lua table与json的之间的互相转换高性能c++实现

    请自行约束两种语言数据结构语法上的不同,避开如下问题: 1.json本身不约束key是否符合一个编程语言中的变量名,所以编写用于和编程语言数据结构交互的json代码时应该注意key是否正确. 2.lu ...

  2. 我为什么要再给lua写一个json模块

    最近要给自己编写的服务器加上json解析模块.根据我当前的项目,可以预测服务器中使用json的地方: 通信.由于与客户端通信使用google protocolbuffer,仅在与SDK通信中使用jso ...

  3. cocos2d-x lua table数据存储

    cocos2d-x lua table数据存储 version: cocos2d-x 3.6 1. 将table转为json http://blog.csdn.net/songcf_faith/art ...

  4. java中Array/List/Map/Object与Json互相转换详解(转载)

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...

  5. ajax-json,遇到的一个问题,jquery var ,加载顺序。JS对象,json格式转换。

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. python 使用json格式转换

    什么是json: JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programm ...

  7. jquery插件-table转Json数据插件

    使 用开源插件Table-to-json: 官方地址:http://lightswitch05.github.io/table-to-json/ 功能说明:将js对象table转换成javascrip ...

  8. lua table integer index 特性

    table.maxn (table) Returns the largest positive numerical index of the given table, or zero if the t ...

  9. json日期转换

    //调用 ChangeDateFormat(CreatTime) //json日期转换 function ChangeDateFormat(jsondate) { jsondate = jsondat ...

随机推荐

  1. Tkinter教程之Toplevel篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811341 '''Tkinter教程之Toplevel篇'''#TopLevel与Frame类 ...

  2. Tkinter教程之Listbox篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811310 #Tkinter教程之Listbox篇#Listbox为列表框控件,它可以包含一个 ...

  3. 纯css3鼠标经过图片显示描述特效

    http://***/Article/5582 今天给大家带来的是用css3技术实现鼠标经过图片,显示图片描述的动画效果.鼠标经过图片时,图片动画缩小并渐变显示描述.我们一起看看效果图: 在线预览   ...

  4. 解决A program file was not specified in the launch configuration.问题

        问题描述: 在eclipse 中开发c++或c是比较麻烦的事情,刚刚配置好mingw32和cdt和环境变量后,新建一个hello world的c++项目还是会出现问题.主要是在编译的时候会提示 ...

  5. SQL入门

    ​ # SQL入门 数据库表 一个数据库(database)通常包含一个或多个表(table). 每一个表都有一个名字标识. 表单包含数据的记录(行). 一些重要的SQL命令(常用的吧) 命令 说明 ...

  6. [LeetCode] #1# Two Sum : 数组/哈希表/二分查找/双指针

    一. 题目 1. Two SumTotal Accepted: 241484 Total Submissions: 1005339 Difficulty: Easy Given an array of ...

  7. HYSBZ 2243-染色 (树链剖分)

    1A!!! 哈哈哈哈哈没看题解 没套模板哈哈哈哈 太感动了!! 如果只是线段树的话这道题倒是不难,只要记录左右边界就好了,类似很久以前做的hotel的题 但是树上相邻的段会有连续的 树上top[x]和 ...

  8. Delimiter must not be alphanumeric or backslash 问题及解决

    Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in 正则表达 ...

  9. URAL 2037 Richness of binary words (回文子串,找规律)

    Richness of binary words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/B Description Fo ...

  10. Web安全--使用Salt + Hash将密码加密后再存储进数据库

    转载原地址 http://www.bozhiyue.com/mianshiti/_net/2016/0728/314239.html (一) 为什么要用哈希函数来加密密码 如果你需要保存密码(比如网站 ...