JSON发布PHP(TypeForm)

编程入门 行业动态 更新时间:2024-10-26 12:31:29
本文介绍了JSON发布PHP(TypeForm)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have never used JSON before so apologies if this is a simple request.

我有一个webhook设置,向我发送JSON帖子(下面的示例)-我想从此"text":"250252"& {"label":"CE"}

I have a webhook setup that sends me a JSON Post (Example Below) - I want to extract the two answers from this "text":"250252" & {"label":"CE"}

{ "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文件中有此文件

I have this currently in my PHP file:

$data = json_decode(file_get_contents('php://input')); $ID = $data->{"text"}; $Skill = $data->{"label"};

这不起作用,我得到的全部为空-谢谢您的帮助.

This does not work and all I get is null - Any help would really be appreciated, Thank You.

推荐答案

使用json_decode后,您需要查看要接收的JSON对象,以了解要接收的对象的结构.尝试获取位于$data->form_response->answers中,因此您可以使用一个变量以方便访问:

You need to look at the JSON object you're receiving to know the structure of the object you're receiving after using json_decode, what you're trying to get is in $data->form_response->answers, So you can have a variable for easier access:

$answers = $data->form_response->answers;

记住$answers是一个数组

因此,要实现您想要获得的目标,您可以执行以下操作:

So to achieve what you're trying to get, you can do:

$data = json_decode(file_get_contents('php://input')); $answers = $data->form_response->answers; $ID = $answers[0]->text; $Skill = $answers[1]->choice->label;

更多推荐

JSON发布PHP(TypeForm)

本文发布于:2023-10-12 01:17:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483344.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JSON   PHP   TypeForm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!