JSON 中的 NULL 常量 (json.null)
聲明
json.null
說明
這不是一個函式,是一個常量。以文字形式列印為 “
userdata: 0x0”
它用於表示 json 中對應的 null 值
為甚麼它有必要存在: Lua table 中的 nil 會被視為不存在,轉換為 JSON 後對應的 key 會消失,因此需要一個特定值來表示 null
該值可在 XUI 中使用
範例
local tb = json.decode('{"nullvalue":null}')
if tb['nullvalue'] == json.null then
sys.alert(json.null)
end
注:上述代碼中使用了非本章函式 sys.alert