【问题标题】:Extract address from Google People JSON object in Podio从 Podio 中的 Google People JSON 对象中提取地址
【发布时间】:2022-01-22 22:55:59
【问题描述】:

我正在尝试从 Podio Workflow Automation 中的 Google People API 调用中提取地址数据。我正在成功提取除地址之外的所有其他数据。

情况 - 如果我只请求姓名,我可以提取每个单独的姓名字段,但如果我将地址添加到请求中,我将无法再提取姓名字段或地址字段。如果我只请求地址,我无法提取地址字段。

由于某种原因,包括地址数据似乎破坏了 JSON..

仅请求姓名数据,我得到:

{
  "resourceName": "people/c2138163302931177819",
  "etag": "%EgUBAi43PRoEAQIFByIMT1hSSUpZWTVuMFk9",
  "names": [
    {
      "metadata": {
        "primary": true,
        "source": {
          "type": "CONTACT",
          "id": "1dac48320efd215b"
        }
      },
      "displayName": "xx xxxxx xxxxxx",
      "familyName": "xxxxxx",
      "givenName": "xxxxx",
      "honorificPrefix": "xx",
      "displayNameLastFirst": "xxxxxx, xx xxxxx",
      "unstructuredName": "xx xxxxx xxxxxx"
    }
  ]
}

请求姓名和地址数据,我得到:

{
  "resourceName": "people/c2138163302931177819",
  "etag": "%EggBAgwQLjc9QBoEAQIFByIMT1hSSUpZWTVuMFk9",
  "names": [
    {
      "metadata": {
        "primary": true,
        "source": {
          "type": "CONTACT",
          "id": "1dac48320efd215b"
        }
      },
      "displayName": "xx xxxxx xxxxxx",
      "familyName": "xxxxxx",
      "givenName": "xxxxx",
      "honorificPrefix": "xx",
      "displayNameLastFirst": "xxxxxx, xx xxxxxx",
      "unstructuredName": "xx xxxxx xxxxxx"
    }
  ],
  "addresses": [
    {
      "metadata": {
        "primary": true,
        "source": {
          "type": "CONTACT",
          "id": "1dac48320efd215b"
        }
      },
      "formattedValue": "xxxxxxx\nSouthampton, England xxxxxxx\nUnited Kingdom",
      "streetAddress": "xxxxxxx",
      "city": "Southampton",
      "region": "England",
      "postalCode": "xxxxxxx",
      "country": "United Kingdom",
      "countryCode": "GB"
    }
  ]
}

对我来说,这在结构上看起来没有什么不同,但是当我将其更改为此处的代码时,它无法正确识别后一个..

在 Podio 中,我对响应进行 base64 编码,然后作为示例提取我使用的名字:

json_decode(base64_decode([(Variable) google_array]))->{'names'}[0]->{'givenName'}

对于我正在使用的城市

json_decode(base64_decode([(Variable) google_array]))->{'addresses'}[0]->{'city'}

如果我只请求姓名详细信息,但如果它还包含地址详细信息,则提取名称可以正常工作。似乎只有地址会造成此问题。我无法提取任何地址详细信息。

【问题讨论】:

  • 看这里的代码我想知道是不是出现在地址 formattedValue 字段中的 /n

标签: json podio google-people-api


【解决方案1】:

听起来您的 json_decode(或编码)不适用于那些“\n”换行符。

请参阅有关 PHP 7 中 json_decode 的讨论:New lines and tabs in json_decode() (PHP 7)

【讨论】:

  • 感谢 marmor - 我会在解码前尝试删除 \n。我实际上根本不需要 formattedValue 信息,所以我想知道是否可以删除该字段..
  • 在 base64 编码之前删除 \n 是一种享受 - 感谢 Marmor
【解决方案2】:

使用 str_replace 在 base64 编码之前从 JSON 响应中删除“\n”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 2013-09-28
    • 1970-01-01
    • 2017-08-12
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多