quick cocos2d-x lua解析json文件

前端之家收集整理的这篇文章主要介绍了quick cocos2d-x lua解析json文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我用的是quick 2.2.6版本!

示例代码如下:

local jsonfile = [[{"age":"25",
"testArray":{"array":[2,3,4,5,6]},
"str":"test json",
"float":"3.14",
"bool":"true"}]];


local data = json.decode(jsonfile)
printf("data age = %d",data["age"])


for i = 1,#data["testArray"]["array"] do
printf("testArray array[%d] === %d",i,data["testArray"]["array"][i])
end
print("data str == ",data["str"])
print("data float == ",data["float"])
print("data bool == ",data["bool"])

log 输出如下:

Cocos2d: [0.1982] data age = 25 Cocos2d: [0.1982] testArray array[1] === 2 Cocos2d: [0.1982] testArray array[2] === 3 Cocos2d: [0.1982] testArray array[3] === 4 Cocos2d: [0.1982] testArray array[4] === 5 Cocos2d: [0.1982] testArray array[5] === 6 Cocos2d: [0.1982] data str == test json Cocos2d: [0.1982] data float == 3.14 Cocos2d: [0.1982] data bool == true

原文链接:https://www.f2er.com/cocos2dx/344063.html

猜你在找的Cocos2d-x相关文章