version: cocos2d-x 3.6
1. 将table转为json
http://blog.csdn.net/songcf_faith/article/details/46389157 http://www.cnblogs.com/songcf/p/4556773.html
1) 引入json库
require("src/cocos/cocos2d/json")
2) 使用json
-- table转json
local jsonData = json.encode(tableData)
-- json转table
local testTable = json.decode(jsonData)
2. 数据持久化
1) 保存json数据
local tableData = json.encode(TABLE_DATA)
local file = io.open(SAVE_PATH,"wb")
file:write(tableData)
io.close(file)
2) 读取json数据
local file = io.open(SAVE_PATH, "rb")
local readjson= file:read("*a") --read all
file:close()
local tableData = json.decode(readjson)
|
请发表评论