<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 20 lua與json Lua-cjson庫的官方網站 [https://www.kyne.com.au/~mark/software/lua-cjson.php](https://www.kyne.com.au/~mark/software/lua-cjson.php) 可以用luarocks安裝cjson庫 ```lua luarocks install lua-cjson ``` ### 例子1 decode--將json字符串解析成lua-table類型 ```lua json_text = '[true, {"foo":"bar"}]' json_value = cjson.decode(json_text) -- Returns: '[true,{"foo":"bar"}]' for key, value in pairs(json_value) do if key == 1 then print(key, value) elseif key == 2 then for k, v in pairs(value) do print(k, v) end end end ``` 結果如下: ```lua 1 true foo bar ``` ```lua local cjson = require "cjson" local sampleJson = [[{"age":"23","testArray":{"array":[8,9,11,14,25]},"Himi":"himigame.com"}]]; --解析json字符串 local data = cjson.decode(sampleJson); --打印json字符串中的age字段 print(data["age"]); --打印數組中的第一個值(lua默認是從0開始計數) print(data["testArray"]["array"][1]); ``` ### ### 例子2 encode--將lua-table類型裝換成json字符串 ```lua local cjson = require "cjson" list = {foo = "bar"} json_str = cjson.encode(list) print(json_str) ``` 結果如下: ```lua {"foo":"bar"} ``` ```lua local cjson = require "cjson" local retTable = {}; --最終產生json的表 --順序數值 local intDatas = {}; intDatas[1] = 100; intDatas[2] = "100"; --數組 local aryDatas = {}; aryDatas[1] = {}; aryDatas[1]["鍵11"] = "值11"; aryDatas[1]["鍵12"] = "值12"; aryDatas[2] = {}; aryDatas[2]["鍵21"] = "值21"; aryDatas[2]["鍵22"] = "值22"; --對Table賦值 retTable["鍵1"] = "值1"; retTable[2] = 123; retTable["int_datas"] = intDatas; retTable["aryDatas"] = aryDatas; --將表數據編碼成json字符串 local jsonStr = cjson.encode(retTable); print(jsonStr); --結果是:{"int_datas":[100,"100"],"2":123,"鍵1":"值1","aryDatas":[{"鍵12":"值12","鍵11":"值11"},{"鍵21":"值21","鍵22":"值22"}]} ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看