본문으로 건너뛰기

json.decode()

JSON 텍스트를 Lua 값으로 디코딩합니다.

시그니처​

json.decode(text: string): any

매개변수​

매개변수유형설명
textstring파싱할 JSON 텍스트

반환값

디코딩된 값입니다. 객체와 배열은 테이블, 그 외에는 문자열, 숫자, 불리언 또는 nil입니다.

설명​

잘못된 JSON은 오류를 발생시킵니다. 서버가 다른 것(예: HTML 오류 페이지)을 반환할 수 있으면 네트워크 입력을 pcall()로 감싸세요.

예시​

local response = Request("https://api.example.com/user/1"):get()
local ok, user = pcall(function()
return json.decode(response:getData())
end)
if ok then
toast("Hello " .. user.name)
end