清理 JSON 数据

发布于 2024-12-16 16:27:25 字数 909 浏览 4 评论 0原文

好的,出于某种原因,当我 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柏拉图鍀咏恒 2024-12-23 16:27:25

使用 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 the json_encode manual page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文