清理 JSON 数据
好的,出于某种原因,当我 print_r my json 时,我得到以下内容
[{"value":{"givenName":"stream","middleName":null,"familyName":"101","prefix":null,"suffix":null,"givenNameSound":null,"familyNameSound":null}}]
,但是值应该 = 电子邮件地址,然后它具有其他字段给定名称等。
我想做的只是打印出 ie [电子邮件受保护]
我将如何使用 PHP 执行此操作。
我目前是如何做的
$contacts = $queryResponse->query->results->contact;
//print_r($contacts);
foreach($contacts as $contact) {
$contact = json_encode($contact);
$contact = json_decode($contact);
if($contact->fields->value != NULL)
{
print "[".json_encode($contact->fields)."]";
//print_r($contact->fields->value);
}
ok for some reason when I print_r my json I get the following
[{"value":{"givenName":"stream","middleName":null,"familyName":"101","prefix":null,"suffix":null,"givenNameSound":null,"familyNameSound":null}}]
however value should = an email address and then it has the other fields givenName etc.
What I want to do is only print out the ones that have value field in ie [email protected]
how would I do this with PHP.
How I am currently doing it
$contacts = $queryResponse->query->results->contact;
//print_r($contacts);
foreach($contacts as $contact) {
$contact = json_encode($contact);
$contact = json_decode($contact);
if($contact->fields->value != NULL)
{
print "[".json_encode($contact->fields)."]";
//print_r($contact->fields->value);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
json_last_error()
来查找。 (升级到 PHP 5.3 进行测试。)每当您在编码的 JSON 字符串中收到
NULL
值时,输入字符集都不是有效的 UTF-8。这是json_encode
手册页中列出的要求之一。Use
json_last_error()
to find out. (Upgrade to PHP 5.3 for testing.)Whenever you receive
NULL
values in the encoded JSON string, the input character set wasn't valid UTF-8. That's one of the requirements listed in thejson_encode
manual page.