2017-02-18 62 views
0

我使用cjson来解码以下JSON。我想测试items参数为null的情况。我很难找到符合这种情况的条件。这很奇怪,因为它似乎不是一个字符串,不是零,但stil具有真正的价值。Lua cjson测试null

{ 
    "kind": "ServiceList", 
    "apiVersion": "v1", 
    "metadata": { 
    "selfLink": "/api/v1/services", 
    "resourceVersion": "47316" 
    }, 
    "items": null 
} 

这里是我已经尝试了条件语句:

if jsonServices.items == "null" then

if jsonServices.items == null then

if not jsonServices.items then

if jsonServices.items == nil

+0

'print(jsonServices.items)'显示什么? – lhf

回答

2

发现this在Lua的文档

if jsonServices.items == cjson.null then

的伟大工程!