문법
json.decodeSafe(json: string, options?: DecodeOptions): boolean | any | nil | string | nil | number | nil인수
| 이름 | 타입 | 설명 |
|---|---|---|
json | string | 구문 분석, 형식화, 축소 또는 검증을 위한 JSON 문자열입니다. |
options? | DecodeOptions | 작업 작동 방식을 제어하는 선택적 설정 테이블입니다. |
반환값
| 이름 | 타입 | 설명 |
|---|---|---|
success | boolean | 작업이 성공적으로 완료되면 True입니다. |
decoded | any | nil | 디코딩된 Luau 값 또는 디코딩된 바이트 문자열입니다. |
errorMessage | string | nil | 로드 또는 구문 분석에 실패하면 오류 메시지가 반환됩니다. 그렇지 않으면 nil입니다. |
errorPosition | number | nil | 구문 분석이 실패한 위치 또는 구문 분석 오류가 발생하지 않은 경우 nil입니다. |
설명
던지지 않고 JSON을 구문 분석하고 성공, 값 및 오류 세부 정보를 반환합니다.
2개 파라미터로 호출합니다: json, options. 인수 표는 필수 값과 동작을 조정하는 값을 설명합니다.
success (boolean), decoded (any | nil), errorMessage (string | nil), errorPosition (number | nil)을 반환합니다. 반환 표를 사용해 성공 값, nil 결과, 복구 가능한 오류를 구분하세요.
예제
오류를 발생시키지 않고 신뢰할 수 없는 JSON을 구문 분석합니다.
local ok, value, message, position = json.decodeSafe('{"ready":true}')
if ok then
print(value.ready)
else
warn(message, position)
end타입
DecodeOptions
JSON 구문 분석 동작을 제어합니다.
useNull? boolean nil 대신 라이브러리의 null 센티널을 사용하여 JSON null을 나타냅니다.maxDepth? integer 1부터 4096까지 고정된 최대 중첩 깊이를 설정합니다.