メインコンテンツまでスキップ

json

すべてのマクロに組み込まれた小さな JSON エンコーダー/デコーダーです。グローバルの json テーブルとして利用でき、Request モジュールと組み合わせると便利です。

メソッド​

メソッド説明
json.encode(value)Lua の値を JSON テキストに変換
json.decode(text)JSON テキストを Lua の値に変換

例​

local body = json.encode({ name = "John", age = 30 })
local response = Request("https://api.example.com/users")
:setHeader("Content-Type", "application/json")
:setBody(body)
:post()
local answer = json.decode(response:getData())
toast("Created user " .. answer.id)