我用的是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