cocos2d-x lua table與json的轉換


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM