zoukankan      html  css  js  c++  java
  • 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:
    " .. jsonData)
    	
    	-- decode
    	testTable = json.decode(jsonData)
    
    	local endTime = os.time()
    	print("test time: " .. tostring(endTime - beginTime))
    end
    
  • 相关阅读:
    HDU 5521 Meeting
    HDU 5170 GTY's math problem
    HDU 5531 Rebuild
    HDU 5534 Partial Tree
    HDU 4101 Ali and Baba
    HDU 5522 Numbers
    HDU 5523 Game
    ZUFE OJ 2301 GW I (3)
    POJ 2398 Toy Storage
    POJ 2318 TOYS
  • 原文地址:https://www.cnblogs.com/songcf/p/4556773.html
Copyright © 2011-2022 走看看