首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSON Post PHP (TypeForm)

JSON Post PHP (TypeForm)
EN

Stack Overflow用户
提问于 2018-05-22 16:58:21
回答 1查看 1.2K关注 0票数 0

如果这是一个简单的请求,我以前从未使用过JSON。

我有一个webhook设置,发送给我一个JSON (下面的例子)--我想从这个"text":"250252" & {"label":"CE"}中提取两个答案

代码语言:javascript
复制
{
  "event_id": "1",
  "event_type": "form_response",
  "form_response": {
    "form_id": "VpWTMQ",
    "token": "1",
    "submitted_at": "2018-05-22T14:11:56Z",
    "definition": {
      "id": "VpWTMQ",
      "title": "SS - Skill Change",
      "fields": [
        {
          "id": "kUbaN0JdLDz8",
          "title": "Please enter your ID",
          "type": "short_text",
          "ref": "9ac66945-899b-448d-859f-70562310ee5d",
          "allow_multiple_selections": false,
          "allow_other_choice": false
        },
        {
          "id": "JQD4ksDpjlln",
          "title": "Please select the skill required",
          "type": "multiple_choice",
          "ref": "a24e6b58-f388-4ea9-9853-75f69e5ca337",
          "allow_multiple_selections": false,
          "allow_other_choice": false
        }
      ]
    },
    "answers": [
      {
        "type": "text",
        "text": "250252",
        "field": {
          "id": "kUbaN0JdLDz8",
          "type": "short_text"
        }
      },
      {
        "type": "choice",
        "choice": {
          "label": "CE"
        },
        "field": {
          "id": "JQD4ksDpjlln",
          "type": "multiple_choice"
        }
      }
    ]
  }
}

我的PHP文件中目前有这样的内容:

代码语言:javascript
复制
$data = json_decode(file_get_contents('php://input'));
$ID = $data->{"text"};
$Skill = $data->{"label"};

这不起作用,我得到的一切都是无效的-任何帮助都将是非常感谢的,谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-22 17:25:52

您需要查看正在接收的JSON对象,以了解在使用json_decode之后接收到的对象的结构,您试图获得的是$data->form_response->answers中的对象,这样您就可以有一个变量以便于访问:

代码语言:javascript
复制
$answers = $data->form_response->answers;

记住$answers是一个数组

因此,为了实现你想要的,你可以:

代码语言:javascript
复制
$data = json_decode(file_get_contents('php://input'));
$answers = $data->form_response->answers;
$ID = $answers[0]->text;
$Skill = $answers[1]->choice->label;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50472952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档