json在php中解码 [英] json decode in php

查看:93
本文介绍了json在php中解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下json字符串,我只想从中检索电子邮件地址.如何在php中做到这一点?

I have the following json string and I want to retrieve just the email address from it. How do I do it in php?

{"communications":{"communication":[{"@array":"true","@id":"23101384","@uri":"xyz/v1/Communications/1111","household":{"@id":"111111","@uri":"xyz/v1/Households/5465465"},"person":{"@id":"","@uri":""},"communicationType":{"@id":"1","@uri":"xyz/v1/Communications/CommunicationTypes/1","name":"Home Phone"},"communicationGeneralType":"Telephone","communicationValue":"1111","searchCommunicationValue":"2693240758","listed":"true","communicationComment":null,"createdDate":"2008-11-10T12:31:26","lastUpdatedDate":"2009-08-11T23:40:02"},{"@array":"true","@id":"11111","@uri":"xyz/v1/Communications/111111111","household":{"@id":"14436295","@uri":"xyz/v1/Households/11111"},"person":{"@id":"2222222","@uri":"xyz/v1/People/22222222"},"communicationType":{"@id":"2","@uri":"xyz/v1/Communications/CommunicationTypes/2","name":"Work Phone"},"communicationGeneralType":"Telephone","communicationValue":"11111","searchCommunicationValue":"789787987","listed":"false","communicationComment":null,"createdDate":"2009-08-09T15:49:27","lastUpdatedDate":"2009-08-11T23:40:02"},{"@array":"true","@id":"11111","@uri":"xyz/v1/Communications/11111","household":{"@id":"1111","@uri":"xyz/v1/Households/1111"},"person":{"@id":"244404","@uri":"xyz/v1/People/1111"},"communicationType":{"@id":"3","@uri":"xyz/v1/Communications/CommunicationTypes/3","name":"Mobile"},"communicationGeneralType":"Telephone","communicationValue":"22222","searchCommunicationValue":"5475454","listed":"true","communicationComment":null,"createdDate":"2008-11-10T12:31:26","lastUpdatedDate":"2009-08-11T23:40:02"},{"@array":"true","@id":"15454","@uri":"xyz/v1/Communications/111111","household":{"@id":"14436295","@uri":"xyz/v1/Households/1111"},"person":{"@id":"244444474","@uri":"xyz/v1/People/111111"},"communicationType":{"@id":"4","@uri":"xyz/v1/Communications/CommunicationTypes/4","name":"Email"},"communicationGeneralType":"Email","communicationValue":"email@needthis.com","searchCommunicationValue":"email@needthis.com","listed":"true","communicationComment":null,"createdDate":"2008-11-10T12:31:26","lastUpdatedDate":"2009-08-11T23:39:06"}]}}

推荐答案

访问它的另一种错误是:

Another twist on how inerte did it would be to access it like:

$json_object = '{"communications":
                       {"communication":
                         [{"@array":"true","@id":"23101384","@uri":"xyz/v1/Communications/1111","household":
                            {"@id":"111111","@uri":"xyz/v1/Households/5465465"},
                            "person": {"@id":"","@uri":""},
                            "communicationType":{"@id":"1","@uri":"xyz/v1/Communications/CommunicationTypes/1","name":"Home Phone"},
                            "communicationGeneralType":"Telephone","communicationValue":"1111","searchCommunicationValue":"2693240758",
                               "listed":"true","communicationComment":null,"createdDate":"2008-11-10T12:31:26","lastUpdatedDate":"2009-08-11T23:40:02"},
                            {"@array":"true","@id":"11111","@uri":"xyz/v1/Communications/111111111","household":
                              {"@id":"14436295","@uri":"xyz/v1/Households/11111"},
                            "person": {"@id":"2222222","@uri":"xyz/v1/People/22222222"},
                            "communicationType": {"@id":"2","@uri":"xyz/v1/Communications/CommunicationTypes/2","name":"Work Phone"},
                            "communicationGeneralType":"Telephone","communicationValue":"11111","searchCommunicationValue":"789787987","listed":"false",
                                "communicationComment":null,"createdDate":"2009-08-09T15:49:27","lastUpdatedDate":"2009-08-11T23:40:02"},
                            {"@array":"true","@id":"11111","@uri":"xyz/v1/Communications/11111","household": {"@id":"1111","@uri":"xyz/v1/Households/1111"},
                            "person":{"@id":"244404","@uri":"xyz/v1/People/1111"},
                            "communicationType":{"@id":"3","@uri":"xyz/v1/Communications/CommunicationTypes/3","name":"Mobile"},
                            "communicationGeneralType":"Telephone","communicationValue":"22222","searchCommunicationValue":"5475454","listed":"true",
                                "communicationComment":null,"createdDate":"2008-11-10T12:31:26","lastUpdatedDate":"2009-08-11T23:40:02"},
                            {"@array":"true","@id":"15454","@uri":"xyz/v1/Communications/111111","household":{"@id":"14436295","@uri":"xyz/v1/Households/1111"},
                            "person":{"@id":"244444474","@uri":"xyz/v1/People/111111"},
                            "communicationType":{"@id":"4","@uri":"xyz/v1/Communications/CommunicationTypes/4","name":"Email"},
                            "communicationGeneralType":"Email","communicationValue":"email@needthis.com","searchCommunicationValue":"email@needthis.com","listed":"true",
                            "communicationComment":null,"createdDate":"2008-11-10T12:31:26","lastUpdatedDate":"2009-08-11T23:39:06"}
                         ]
                       }
                      }';


    $json_decoded = json_decode($json_object);
    echo "email: ".$json_decoded->communications->communication[3]->communicationValue."<br />";

这篇关于json在php中解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆