如何从Zoho Deluge的Incoming Webhook的请求体中访问嵌套JSON的键值

huangapple go评论72阅读模式
英文:

How to access key's value from nested JSON in body of Incoming Webhook on Zoho Deluge

问题

尝试使用 MailChimp 出站 Webhook 来通过 Zoho 的传入 Webhook 功能同步 Zoho 联系人,但无法找到如何从发送到传入 Webhook 的“body”中访问“email”值的方法。

发送到 Webhook 的 body =

{"body":"{ \"type\": \"subscribe\", \"fired_at\": \"2009-03-26 21:35:57\", \"data\": { \"id\": \"8a25ff1d98\", \"list_id\": \"a6b5da1054\", \"email\": \"api@mailchimp.com\", \"email_type\": \"html\", \"ip_opt\": \"10.20.10.30\", \"ip_signup\": \"10.20.10.30\" \"merges\": { \"EMAIL\": \"api@mailchimp.com\", \"FNAME\": \"Mailchimp\", \"LNAME\": \"API\", \"INTERESTS\": \"Group1,Group2\" } } }"}

我正在使用以下简单代码将字符串 body 转换为 JSON:

responseBody = body.getJSON("body");
info "responseBody= "+ responseBody;

示例输出:
body= { "type": "subscribe", "fired_at": "2009-03-26 21:35:57", "data": { "id": "8a25ff1d98", "list_id": "a6b5da1054", "email": "api@mailchimp.com", "email_type": "html", "ip_opt": "10.20.10.30", "ip_signup": "10.20.10.30" "merges": { "EMAIL": "api@mailchimp.com", "FNAME": "Mailchimp", "LNAME": "API", "INTERESTS": "Group1,Group2" } } }

我假设我需要将 body 字符串转换为 JSON,然后使用 GetJSON 访问,但无论我尝试什么,都返回 NULL。

如何将 Email 的值获取到一个变量中,以便在我的 deluge 函数中使用?

相关链接:
https://www.zoho.com/deluge/help/functions/common/getjson.html
https://www.zoho.com/deluge/help/functions/text.html

我尝试将其转换回 JSON、集合和映射,但无法从 Body->Data->email 中获取值。

body.getJSON("data")responseBody.getJSON("data") 都返回 null,这在调试信息中显示它是格式正确的 JSON 的情况下没有意义。

可能的问题是,在 Zoho 上,集合需要是一个简单列表或键/值对列表,而我的 body 包含了两者的混合。

英文:

Attempting to use MailChimp outbound Webhook to sync Zoho Contacts via Zoho's Incoming Webhook functionality and can't figure out how to access the value of "email" from the "body" sent to Incoming Webhook.

body being sent to webhook=

{"body":"{ \"type\": \"subscribe\", \"fired_at\": \"2009-03-26 21:35:57\", \"data\": { \"id\": \"8a25ff1d98\", \"list_id\": \"a6b5da1054\", \"email\": \"api@mailchimp.com\", \"email_type\": \"html\", \"ip_opt\": \"10.20.10.30\", \"ip_signup\": \"10.20.10.30\" \"merges\": { \"EMAIL\": \"api@mailchimp.com\", \"FNAME\": \"Mailchimp\", \"LNAME\": \"API\", \"INTERESTS\": \"Group1,Group2\" } } }"}

Simple code I am using to cast the string body to JSON.

responseBody = body.getJSON("body");
info "responseBody= "+ responseBody;

EXAMPLE OUTPUT:
body= { "type": "subscribe", "fired_at": "2009-03-26 21:35:57", "data": { "id": "8a25ff1d98", "list_id": "a6b5da1054", "email": "api@mailchimp.com", "email_type": "html", "ip_opt": "10.20.10.30", "ip_signup": "10.20.10.30" "merges": { "EMAIL": "api@mailchimp.com", "FNAME": "Mailchimp", "LNAME": "API", "INTERESTS": "Group1,Group2" } } }

I am assuming I need to cast the body string to JSONand then access using GetJSON, but everything I try is
returning NULL.

How can I get the value of Email into a variable to use in my deluge function?

Related:
https://www.zoho.com/deluge/help/functions/common/getjson.html
https://www.zoho.com/deluge/help/functions/text.html

I have tried casting it back to JSON, a Collection and a Map and nothing is letting me get the value from Body->Data->email.

I have tried getJSON(), get() and getKey() and can not get anything other than the top array cast to a variable.

body.getJSON("data") and responseBody.getJSON("data") both return null which makes no sense given debug 'info' shows it is properly formatted JSON.

Possible the issue is that Collection on Zoho needs to be either a simple list or a list of key/value pairs, and my body is a mix of both.

答案1

得分: 1

错误的原因是你提到的 Webhook 发送的主体格式是错误的,在 "ip_signup" 和 "merges" 之间,缺少了逗号,应该有逗号。

如何从Zoho Deluge的Incoming Webhook的请求体中访问嵌套JSON的键值

英文:

the reason for the error is the body sent in the webhook that you mentioned is INCORRECT format, look between the key of "ip_signup" and "merges", there is "NO COMMA". it should HAVE COMMA.
如何从Zoho Deluge的Incoming Webhook的请求体中访问嵌套JSON的键值

huangapple
  • 本文由 发表于 2023年4月7日 02:02:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定