0

我有一个已解码为此的 json 对象:

item_json:stdClass Object
(
    [code] => 2013CA
    [SP] => stdClass Object
        (
            [PID] => 1175630
            [FirstName] => Kim
            [LastName] => Kardashian
            [DOB] => 01-02-1978
            [Address1] => 12345 Kardashian Way
            [Address2] => 
            [Address3] => 
            [City] => Hollywood
            [State] => CA
            [Zip] => 90210
            [Country] => US
            [Phone] => 1-210-5551212-
            [Email] => kkardashian@kkardashian.com
            [Info] => stdClass Object
                (
                    [Declined] => null
                    [NameOnLicense] => KK
                    [State] => CA
                    [License] => 90210
                    [LicenseText] => License Number
                    [TypeID] => 215057
                    [Hours] => 24
                    [Units] => 24
                    [Price] => 0
                )

        )

)

如何测试 Info->Declined 是否为空?

我试过了

!isset($item_json-SP->Info->Declined) 

$item_json-SP->Info->Declined == null

但他们都失败了。

4

2 回答 2

1

试试这个

if ($item_json->SP->Info->Declined == null)

你这里有一个错误 $item_json-SP 它不是一个 this 操作符,你有语法错误那里,有内置的 PHP 来检查空值

if(is_null($json->SP->Info->Declined)) {
}
于 2013-05-10T16:32:24.230 回答
1

测试一个值是否NULL是使用is_null()函数的首选方法。进一步注意,正确的路径Declined,它的:SP->Info->Declined。试试这个:

if(is_null($json->SP->Info->Declined)) {

}
于 2013-05-10T16:32:39.920 回答