文章目录
</div>


<h3 id="json字符串转为table"><a href="#json字符串转为table" class="headerlink" title="json字符串转为table"></a>json字符串转为table</h3><figure class="highlight plain"><table><tbody><tr><td class="code"><pre><div class="line">local cjson = require &#34;cjson&#34;</div><div class="line">local json = [[</div><div class="line">    {</div><div class="line">        &#34;name&#34;: &#34;御风小栈&#34;,</div><div class="line">        &#34;url&#34;: &#34;http://www.x86.pub&#34;</div><div class="line">    }</div><div class="line">]]</div><div class="line">local table = cjson.decode(json)</div><div class="line">print(table[&#34;name&#34;], table[&#34;url&#34;])</div></pre></td></tr></tbody></table></figure>

table转为json字符串

local cjson = require "cjson"
local table = {}
table["name"] = "御风小栈"
table["url"] = "http://www.x86.pub"
local json = cjson.encode(table)
print(json)