【发布时间】:2014-10-14 14:55:34
【问题描述】:
我有一个 Json 字符串,我正在使用 php 的 json_decode 对其进行解码。
字符串
"address": {
"address": null,
"postalCode": null,
"phoneNumber": "",
"city": null
}
当我解码得到的字符串时
["address"]=>
array(1) {
["phoneNumber"]=>
string(0) ""
它本质上是去除带有 null 值的属性,即地址、城市。我可以防止这种情况发生吗?
完整的 JSON
{"cost": null,
"receiptNumber": null,
"receiptType": null,
"labNo": 596726,
"parentLabNo": 0,
"investigation": "BS for mps",
"patient": {
"id": 168967,
"fullName": "UVOGIN",
"dateOfBirth": "1972-04-04 00:00:00",
"gender": "Male"
},
"address": {
"address": null,
"postalCode": null,
"phoneNumber": "",
"city": null
}
}
【问题讨论】:
-
无论如何,理论上
null与一开始就没有定义是一样的。这就是为什么未定义的变量在访问时被视为 null。 -
提供完整的 JSON
-
添加了完整的 json @Dharam
-
@h2ooooooo 你是对的,别的东西正在吞噬我的空值。