dongpeng8994
2014-10-14 14:55
浏览 228
已采纳

php json_decode删除具有null值的属性

I have a Json string and I am decoding it using php's json_decode.

The string

            "address": {
                "address": null,
                "postalCode": null,
                "phoneNumber": "",
                "city": null
            }

When I decode the string I get

            ["address"]=>
                  array(1) {
                  ["phoneNumber"]=>
                       string(0) ""

It essentially strips the attributes with null as a value i.e address, city. Can I prevent this from happening.

COMPLETE 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
            }
        }

图片转代码服务由CSDN问答提供 功能建议

我有一个Json字符串,我使用php的json_decode解码它。

字符串

 “address”:{
“address”:null,
“postalCode”:null,
“phoneNumber”:“”,
“  city“:null 
} 
   
 
 

当我解码字符串时我得到

  [”address“]  => 
 array(1){
 [“phoneNumber”] => 
 string(0)“”
   
 
 

它实际上剥离了属性 使用null作为值,即地址,城市。 我能否防止这种情况发生。

COMPLETE JSON
  {“cost”:null,
“receiptNumber”:null,\  n“receiptType”:null,
“labNo”:596726,
“parentLabNo”:0,
“survey”:“BS for mps”,
“patient”:{
“id”:168967,  
“fullName”:“UVOGIN”,
“dateOfBirth”:“1972-04-04 00:00:00”,
“性别”:“男性”
},
“地址”:{\  n“address”:null,
“postalCode”:null,
“phoneNumber”:“”,
“city”:null 
} 
} 
   
 <  / DIV>

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题