如何将 JSON 结果拆分为多个 Zapier 资产?
How to split JSON results in to multiple Zapier assets?
我的目标是调用 Bing News Search via API 以获得与特定查询匹配的结果。
我正在使用 Zapier. I am using the Code step,它可以使用 Python 或 Javascript。
我目前有 Python 代码调用 API 如下...
headers = {
'Content-Type': 'text/plain',
'Ocp-Apim-Subscription-Key': 'my_api_key'
}
r = requests.get('https://api.cognitive.microsoft.com/bing/v7.0/news/search?q=%22Donald%20Trump%22&textDecorations=true&textFormat=HTML&sortBy=Date&freshness=Day', headers=headers)
output = [{'assets': r.json()}]
这很好用。成功调用并得到结果。
问题是,当我想在后续的 Zapier 步骤中使用这些结果的内容时,它们都在同一个响应对象中混合在一起 - 也就是说,来自多个返回的每个等效值内部故事对象全部放置在相同的可用 Zapier 值 中,以逗号分隔。
示例:对于对象中返回的 10 个故事,可用的 "category" 值为 "null, null, null, World, null, Politics, Politics, Politics, null, null" - 但对于一个故事,它应该只是其中之一。
换句话说,我如何个性化 assets/objects 以便让 Zapier 单独处理它们?
我想说这不仅仅是解析值,而是以 Zapier 可以理解的方式进行解析。但是,我以前用不同的语言做过一次...
为了同样的原则,我有一个单独的 zap 用于另一个目的,它做类似的事情。它接收传入的 Gmail 电子邮件并检查正文 (inputData.body) 中是否有匹配特定模式的字符串。可能有多个这样的字符串。对于其中的每一个,以下 Javascript 将每个 多个 分别传递到下一个 Zapier 步骤。
// stores an array of any length (0 or more) with the matches
var matches = inputData.body.match(/\b[\w-]{32}\b/g)
if (matches == null) {
return { str: "false" }
}
return matches.map(function (m) { return {str: m} })
这神奇地让我的后续 zap 步骤仅针对单个字符串起作用,而不是一组多个字符串。 如何在上面的 API 代码中实现类似的效果?
每个代码示例的最后几行似乎掌握了关键...在 Javascript 中,映射某事某事某事...?
这是每个请求的示例响应...
{
"_type": "News",
"readLink": "https://api.cognitive.microsoft.com/api/v7/news/search?q=%22Donald+Trump%22",
"queryContext": {
"originalQuery": "\"Donald Trump\"",
"adultIntent": false
},
"totalEstimatedMatches": 73200,
"sort": [
{
"name": "Best match",
"id": "relevance",
"isSelected": false,
"url": "https://api.cognitive.microsoft.com/api/v7/news/search?q=%22Donald+Trump%22"
},
{
"name": "Most recent",
"id": "date",
"isSelected": true,
"url": "https://api.cognitive.microsoft.com/api/v7/news/search?q=%22Donald+Trump%22&sortby=date"
}
],
"value": [
{
"name": "Democrats to <b>Donald Trump</b>: Here's a Bill to Outlaw Family Separation",
"url": "https://www.rollingstone.com/politics/news/democrats-give-trump-a-bill-to-outlaw-family-separation-w521650",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.E5F488C11B8B2C7578200936C34BA0C3&pid=News",
"width": 700,
"height": 394
}
},
"description": "All 49 Democrats in the Senate have signed on to a bill that would end Trump's policy of "child-snatching" A two-year-old Honduran asylum seeker cries as her mother is searched and detained near the U.S.-Mexico border on June 12th, 2018 in McAllen, Texas.",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/5e00ddc3-bb67-a2c7-702a-929095be2f19",
"name": "Bill"
}
],
"provider": [
{
"_type": "Organization",
"name": "Rolling Stone"
}
],
"datePublished": "2018-06-19T09:39:00.0000000Z",
"category": "Politics"
},
{
"name": "Republicans break from Trump on migrant family separation",
"url": "https://www.nbcnews.com/politics/first-read/republicans-break-trump-migrant-family-separation-n884171",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.7225F1783FD189C842151F29E579409A&pid=News",
"width": 700,
"height": 367
}
},
"description": "WASHINGTON — The lowest points of <b>Donald Trump</b>’s presidency have tended to occur when a sizable portion of his own party has criticized him for his actions, policies and statements (even when the GOP doesn’t necessarily act on that criticism).",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
}
],
"provider": [
{
"_type": "Organization",
"name": "NBC News"
}
],
"datePublished": "2018-06-19T09:38:00.0000000Z",
"category": "Politics"
},
{
"name": "Anger mounts against Trump over child separation policy",
"url": "https://www.aljazeera.com/news/2018/06/anger-mounts-trump-child-separation-policy-180618071221478.html",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.B6724EE606A4241FC8E9441331E20A67&pid=News",
"width": 700,
"height": 392
}
},
"description": "Pressure is mounting on US President <b>Donald Trump</b> to reverse his policy of separating children from refugees and migrants who cross the US-Mexico border. "Families belong together," protesters chanted on Sunday, as hundreds gathered outside detention ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
}
],
"provider": [
{
"_type": "Organization",
"name": "Al Jazeera English"
}
],
"datePublished": "2018-06-19T09:38:00.0000000Z",
"category": "Politics"
},
{
"name": "President Trump Defends Immigration Policy, Says He Won't Let U.S. Became a 'Migrant Camp'",
"url": "https://www.msn.com/en-us/news/other/president-trump-defends-immigration-policy-says-he-wont-let-us-became-a-migrant-camp/ar-AAyOCt4",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.303D80992671B38688C86FEFC0F5F4B2&pid=News",
"width": 700,
"height": 498
}
},
"description": "WASHINGTON — Facing rising outrage from some Republicans as well as Democrats over the forced separation of migrant children and parents at the U.S.-Mexico border, President <b>Donald Trump</b> dug in Monday, again falsely blaming Democrats and declaring he ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
}
],
"mentions": [
{
"name": "Donald Trump"
},
{
"name": "United States"
},
{
"name": "Migrant worker"
}
],
"provider": [
{
"_type": "Organization",
"name": "Time"
}
],
"datePublished": "2018-06-19T09:36:00.0000000Z",
"category": "Politics"
},
{
"name": "Watch: <b>Donald Trump</b> awkwardly salutes a North Korean general at Singapore summit",
"url": "https://scroll.in/video/882762/watch-donald-trump-awkwardly-salutes-a-north-korean-general-at-singapore-summit",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.D99B1336CDD2C22BFBD080E78C100052&pid=News",
"width": 600,
"height": 315
}
},
"description": "The North Korean state media aired a documentary on the recent Singapore summit, showing the meeting between Kim Jong Un and <b>Donald Trump</b>. Naturally, it wasn’t what the world had seen till then. While the 42-minute long KCTV documentary showed the entire ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/f5ffb882-7230-f3fe-7141-cde5f4b5ed1a",
"name": "Singapore"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/f28f12db-bc21-69f9-3860-1b24810b64ec",
"name": "Salute"
}
],
"provider": [
{
"_type": "Organization",
"name": "Scroll"
}
],
"datePublished": "2018-06-19T09:35:00.0000000Z",
"category": "World"
},
{
"name": "China accuses US of blackmailing after <b>Donald Trump</b>'s tariff threat",
"url": "http://www.newindianexpress.com/world/2018/jun/19/china-accuses-us-of-blackmailing-after-donald-trumps-tariff-threat-1830391.html",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.6A02D23B98FB3695CB79863006E25D86&pid=News",
"width": 600,
"height": 300
}
},
"description": "BEIJING: China today accused the US of "blackmailing" by threatening to slap additional tariffs on USD 200 billion of Chinese goods and warned that it would hit back with comprehensive measures if Washington went ahead with the plan. China's response came ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/5fcc3d97-0cf2-94e5-6dad-cd70e387bd69",
"name": "China"
}
],
"provider": [
{
"_type": "Organization",
"name": "The New Indian Express"
}
],
"datePublished": "2018-06-19T09:35:00.0000000Z",
"category": "Business"
},
{
"name": "Family unity must be preserved: UN Chief Antonio Guterres on <b>Donald Trump</b>'s zero-tolerance immigration policy",
"url": "http://www.newindianexpress.com/world/2018/jun/19/family-unity-must-be-preserved-un-chief-antonio-guterres-on-donald-trumps-zero-tolerance-immigrati-1830399.html",
"description": "UNITED NATIONS: Children must not be traumatised by being separated from their parents, UN chief Antonio Guterres has said amid a growing backlash over US President <b>Donald Trump</b>'s hardline immigration policy which has resulted in the separation of hundreds ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/cba2f3bb-4714-89f7-8cd3-9cc8644da24b",
"name": "Zero tolerance"
}
],
"provider": [
{
"_type": "Organization",
"name": "The New Indian Express"
}
],
"datePublished": "2018-06-19T09:35:00.0000000Z"
},
{
"name": "<b>Donald Trump</b> has ordered the Pentagon to create the US Space Force",
"url": "https://www.technologyreview.com/the-download/611499/donald-trump-has-ordered-the-pentagon-to-create-the-us-space-force/",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.D9DA1E8B8E5DA38E7C6F5D6F5D3FD23C&pid=News",
"width": 700,
"height": 393
}
},
"description": "The Space Force would constitute the sixth branch of the US armed forces. The news: During a meeting with the National Space Council today, President <b>Donald Trump</b> directed the Department of Defense and the Pentagon to begin work on the creation of the ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/f8e3b5fa-8d72-5bd7-c9c1-24ef1caf555a",
"name": "The Pentagon"
}
],
"provider": [
{
"_type": "Organization",
"name": "MIT Technology Review"
}
],
"datePublished": "2018-06-19T09:32:00.0000000Z"
},
{
"name": "Melania Trump “Hates To See” Children Separated From Their Families At Borders",
"url": "http://miami.cbslocal.com/2018/06/17/melania-trump-hates-children-separated-families/",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.E7697BA498AEE34B1399416F5C5B00DF&pid=News",
"width": 700,
"height": 466
}
},
"description": "President <b>Donald Trump</b> has repeatedly blamed the Democrats for the situation despite his administration instituting the policy change. “Democrats can fix their forced family breakup at the Border by working with Republicans on new legislation ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/6f7c7020-66da-2934-a3bb-190380654848",
"name": "Melania Trump"
}
],
"mentions": [
{
"name": "Melania Trump"
},
{
"name": "WFOR-TV"
},
{
"name": "Child"
}
],
"provider": [
{
"_type": "Organization",
"name": "CBS Miami"
}
],
"datePublished": "2018-06-19T09:32:00.0000000Z",
"category": "Politics"
},
{
"name": "Prince Harry said 'give <b>Donald Trump</b> a chance,' says Meghan Markle's father",
"url": "https://www.stuff.co.nz/life-style/104818877/Prince-Harry-said-give-Donald-Trump-a-chance-says-Meghan-Markles-father",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.A5CE69ACF78448306EA41B1A47CCD62E&pid=News",
"width": 620,
"height": 349
}
},
"description": "Meghan Markle's father said that Prince Harry told him to give <b>Donald Trump</b> a chance and suggested that he was open about Britain's withdrawal from the European Union. In a lengthy interview with the British broadcaster ITV, Thomas Markle said Harry was an ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/ae7736c2-4291-bc85-8732-6d20c29ff943",
"name": "Prince Harry"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/e4308957-a185-03fa-10ed-3c7b47fd0aea",
"name": "Meghan Markle"
}
],
"provider": [
{
"_type": "Organization",
"name": "Stuff.co.nz"
}
],
"datePublished": "2018-06-19T09:31:00.0000000Z"
}
]
}
来自 Zapier 平台团队的大卫。
听起来您似乎明白了上面的 Python 部分,但我想稍微解释一下发生了什么。从代码步骤返回项目时,可能会发生以下情况:
- 如果返回的结构是
object
(python 的 dict
),所有的键都将被展平,数组将被整理,在上面的屏幕截图中给出结果
- 如果返回的结构是
array
/list
,后续步骤将为返回列表中的每个项目(您想要的行为)运行
最初,您返回的 dict 具有顶级资产密钥,这具有不良行为。现在,您要返回一个 list 文章,这正是您想要的。
如果您还有其他问题,请告诉我!
不确定您是否曾经使用过此功能,但是 Zapier Formatter>Text>Split Text 现在有一个 'Segment Index' 选项,它将 return 'All (as Separate Fields)'。您将获得多个输出,您可以在后续步骤中选择这些输出。
我的目标是调用 Bing News Search via API 以获得与特定查询匹配的结果。
我正在使用 Zapier. I am using the Code step,它可以使用 Python 或 Javascript。 我目前有 Python 代码调用 API 如下...
headers = {
'Content-Type': 'text/plain',
'Ocp-Apim-Subscription-Key': 'my_api_key'
}
r = requests.get('https://api.cognitive.microsoft.com/bing/v7.0/news/search?q=%22Donald%20Trump%22&textDecorations=true&textFormat=HTML&sortBy=Date&freshness=Day', headers=headers)
output = [{'assets': r.json()}]
这很好用。成功调用并得到结果。
问题是,当我想在后续的 Zapier 步骤中使用这些结果的内容时,它们都在同一个响应对象中混合在一起 - 也就是说,来自多个返回的每个等效值内部故事对象全部放置在相同的可用 Zapier 值 中,以逗号分隔。
示例:对于对象中返回的 10 个故事,可用的 "category" 值为 "null, null, null, World, null, Politics, Politics, Politics, null, null" - 但对于一个故事,它应该只是其中之一。
换句话说,我如何个性化 assets/objects 以便让 Zapier 单独处理它们?
我想说这不仅仅是解析值,而是以 Zapier 可以理解的方式进行解析。但是,我以前用不同的语言做过一次...
为了同样的原则,我有一个单独的 zap 用于另一个目的,它做类似的事情。它接收传入的 Gmail 电子邮件并检查正文 (inputData.body) 中是否有匹配特定模式的字符串。可能有多个这样的字符串。对于其中的每一个,以下 Javascript 将每个 多个 分别传递到下一个 Zapier 步骤。
// stores an array of any length (0 or more) with the matches
var matches = inputData.body.match(/\b[\w-]{32}\b/g)
if (matches == null) {
return { str: "false" }
}
return matches.map(function (m) { return {str: m} })
这神奇地让我的后续 zap 步骤仅针对单个字符串起作用,而不是一组多个字符串。 如何在上面的 API 代码中实现类似的效果?
每个代码示例的最后几行似乎掌握了关键...在 Javascript 中,映射某事某事某事...?
这是每个请求的示例响应...
{
"_type": "News",
"readLink": "https://api.cognitive.microsoft.com/api/v7/news/search?q=%22Donald+Trump%22",
"queryContext": {
"originalQuery": "\"Donald Trump\"",
"adultIntent": false
},
"totalEstimatedMatches": 73200,
"sort": [
{
"name": "Best match",
"id": "relevance",
"isSelected": false,
"url": "https://api.cognitive.microsoft.com/api/v7/news/search?q=%22Donald+Trump%22"
},
{
"name": "Most recent",
"id": "date",
"isSelected": true,
"url": "https://api.cognitive.microsoft.com/api/v7/news/search?q=%22Donald+Trump%22&sortby=date"
}
],
"value": [
{
"name": "Democrats to <b>Donald Trump</b>: Here's a Bill to Outlaw Family Separation",
"url": "https://www.rollingstone.com/politics/news/democrats-give-trump-a-bill-to-outlaw-family-separation-w521650",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.E5F488C11B8B2C7578200936C34BA0C3&pid=News",
"width": 700,
"height": 394
}
},
"description": "All 49 Democrats in the Senate have signed on to a bill that would end Trump's policy of "child-snatching" A two-year-old Honduran asylum seeker cries as her mother is searched and detained near the U.S.-Mexico border on June 12th, 2018 in McAllen, Texas.",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/5e00ddc3-bb67-a2c7-702a-929095be2f19",
"name": "Bill"
}
],
"provider": [
{
"_type": "Organization",
"name": "Rolling Stone"
}
],
"datePublished": "2018-06-19T09:39:00.0000000Z",
"category": "Politics"
},
{
"name": "Republicans break from Trump on migrant family separation",
"url": "https://www.nbcnews.com/politics/first-read/republicans-break-trump-migrant-family-separation-n884171",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.7225F1783FD189C842151F29E579409A&pid=News",
"width": 700,
"height": 367
}
},
"description": "WASHINGTON — The lowest points of <b>Donald Trump</b>’s presidency have tended to occur when a sizable portion of his own party has criticized him for his actions, policies and statements (even when the GOP doesn’t necessarily act on that criticism).",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
}
],
"provider": [
{
"_type": "Organization",
"name": "NBC News"
}
],
"datePublished": "2018-06-19T09:38:00.0000000Z",
"category": "Politics"
},
{
"name": "Anger mounts against Trump over child separation policy",
"url": "https://www.aljazeera.com/news/2018/06/anger-mounts-trump-child-separation-policy-180618071221478.html",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.B6724EE606A4241FC8E9441331E20A67&pid=News",
"width": 700,
"height": 392
}
},
"description": "Pressure is mounting on US President <b>Donald Trump</b> to reverse his policy of separating children from refugees and migrants who cross the US-Mexico border. "Families belong together," protesters chanted on Sunday, as hundreds gathered outside detention ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
}
],
"provider": [
{
"_type": "Organization",
"name": "Al Jazeera English"
}
],
"datePublished": "2018-06-19T09:38:00.0000000Z",
"category": "Politics"
},
{
"name": "President Trump Defends Immigration Policy, Says He Won't Let U.S. Became a 'Migrant Camp'",
"url": "https://www.msn.com/en-us/news/other/president-trump-defends-immigration-policy-says-he-wont-let-us-became-a-migrant-camp/ar-AAyOCt4",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.303D80992671B38688C86FEFC0F5F4B2&pid=News",
"width": 700,
"height": 498
}
},
"description": "WASHINGTON — Facing rising outrage from some Republicans as well as Democrats over the forced separation of migrant children and parents at the U.S.-Mexico border, President <b>Donald Trump</b> dug in Monday, again falsely blaming Democrats and declaring he ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
}
],
"mentions": [
{
"name": "Donald Trump"
},
{
"name": "United States"
},
{
"name": "Migrant worker"
}
],
"provider": [
{
"_type": "Organization",
"name": "Time"
}
],
"datePublished": "2018-06-19T09:36:00.0000000Z",
"category": "Politics"
},
{
"name": "Watch: <b>Donald Trump</b> awkwardly salutes a North Korean general at Singapore summit",
"url": "https://scroll.in/video/882762/watch-donald-trump-awkwardly-salutes-a-north-korean-general-at-singapore-summit",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.D99B1336CDD2C22BFBD080E78C100052&pid=News",
"width": 600,
"height": 315
}
},
"description": "The North Korean state media aired a documentary on the recent Singapore summit, showing the meeting between Kim Jong Un and <b>Donald Trump</b>. Naturally, it wasn’t what the world had seen till then. While the 42-minute long KCTV documentary showed the entire ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/f5ffb882-7230-f3fe-7141-cde5f4b5ed1a",
"name": "Singapore"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/f28f12db-bc21-69f9-3860-1b24810b64ec",
"name": "Salute"
}
],
"provider": [
{
"_type": "Organization",
"name": "Scroll"
}
],
"datePublished": "2018-06-19T09:35:00.0000000Z",
"category": "World"
},
{
"name": "China accuses US of blackmailing after <b>Donald Trump</b>'s tariff threat",
"url": "http://www.newindianexpress.com/world/2018/jun/19/china-accuses-us-of-blackmailing-after-donald-trumps-tariff-threat-1830391.html",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.6A02D23B98FB3695CB79863006E25D86&pid=News",
"width": 600,
"height": 300
}
},
"description": "BEIJING: China today accused the US of "blackmailing" by threatening to slap additional tariffs on USD 200 billion of Chinese goods and warned that it would hit back with comprehensive measures if Washington went ahead with the plan. China's response came ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/5fcc3d97-0cf2-94e5-6dad-cd70e387bd69",
"name": "China"
}
],
"provider": [
{
"_type": "Organization",
"name": "The New Indian Express"
}
],
"datePublished": "2018-06-19T09:35:00.0000000Z",
"category": "Business"
},
{
"name": "Family unity must be preserved: UN Chief Antonio Guterres on <b>Donald Trump</b>'s zero-tolerance immigration policy",
"url": "http://www.newindianexpress.com/world/2018/jun/19/family-unity-must-be-preserved-un-chief-antonio-guterres-on-donald-trumps-zero-tolerance-immigrati-1830399.html",
"description": "UNITED NATIONS: Children must not be traumatised by being separated from their parents, UN chief Antonio Guterres has said amid a growing backlash over US President <b>Donald Trump</b>'s hardline immigration policy which has resulted in the separation of hundreds ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/cba2f3bb-4714-89f7-8cd3-9cc8644da24b",
"name": "Zero tolerance"
}
],
"provider": [
{
"_type": "Organization",
"name": "The New Indian Express"
}
],
"datePublished": "2018-06-19T09:35:00.0000000Z"
},
{
"name": "<b>Donald Trump</b> has ordered the Pentagon to create the US Space Force",
"url": "https://www.technologyreview.com/the-download/611499/donald-trump-has-ordered-the-pentagon-to-create-the-us-space-force/",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.D9DA1E8B8E5DA38E7C6F5D6F5D3FD23C&pid=News",
"width": 700,
"height": 393
}
},
"description": "The Space Force would constitute the sixth branch of the US armed forces. The news: During a meeting with the National Space Council today, President <b>Donald Trump</b> directed the Department of Defense and the Pentagon to begin work on the creation of the ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/f8e3b5fa-8d72-5bd7-c9c1-24ef1caf555a",
"name": "The Pentagon"
}
],
"provider": [
{
"_type": "Organization",
"name": "MIT Technology Review"
}
],
"datePublished": "2018-06-19T09:32:00.0000000Z"
},
{
"name": "Melania Trump “Hates To See” Children Separated From Their Families At Borders",
"url": "http://miami.cbslocal.com/2018/06/17/melania-trump-hates-children-separated-families/",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.E7697BA498AEE34B1399416F5C5B00DF&pid=News",
"width": 700,
"height": 466
}
},
"description": "President <b>Donald Trump</b> has repeatedly blamed the Democrats for the situation despite his administration instituting the policy change. “Democrats can fix their forced family breakup at the Border by working with Republicans on new legislation ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/6f7c7020-66da-2934-a3bb-190380654848",
"name": "Melania Trump"
}
],
"mentions": [
{
"name": "Melania Trump"
},
{
"name": "WFOR-TV"
},
{
"name": "Child"
}
],
"provider": [
{
"_type": "Organization",
"name": "CBS Miami"
}
],
"datePublished": "2018-06-19T09:32:00.0000000Z",
"category": "Politics"
},
{
"name": "Prince Harry said 'give <b>Donald Trump</b> a chance,' says Meghan Markle's father",
"url": "https://www.stuff.co.nz/life-style/104818877/Prince-Harry-said-give-Donald-Trump-a-chance-says-Meghan-Markles-father",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.A5CE69ACF78448306EA41B1A47CCD62E&pid=News",
"width": 620,
"height": 349
}
},
"description": "Meghan Markle's father said that Prince Harry told him to give <b>Donald Trump</b> a chance and suggested that he was open about Britain's withdrawal from the European Union. In a lengthy interview with the British broadcaster ITV, Thomas Markle said Harry was an ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/ae7736c2-4291-bc85-8732-6d20c29ff943",
"name": "Prince Harry"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/e4308957-a185-03fa-10ed-3c7b47fd0aea",
"name": "Meghan Markle"
}
],
"provider": [
{
"_type": "Organization",
"name": "Stuff.co.nz"
}
],
"datePublished": "2018-06-19T09:31:00.0000000Z"
}
]
}
来自 Zapier 平台团队的大卫。
听起来您似乎明白了上面的 Python 部分,但我想稍微解释一下发生了什么。从代码步骤返回项目时,可能会发生以下情况:
- 如果返回的结构是
object
(python 的dict
),所有的键都将被展平,数组将被整理,在上面的屏幕截图中给出结果 - 如果返回的结构是
array
/list
,后续步骤将为返回列表中的每个项目(您想要的行为)运行
最初,您返回的 dict 具有顶级资产密钥,这具有不良行为。现在,您要返回一个 list 文章,这正是您想要的。
如果您还有其他问题,请告诉我!
不确定您是否曾经使用过此功能,但是 Zapier Formatter>Text>Split Text 现在有一个 'Segment Index' 选项,它将 return 'All (as Separate Fields)'。您将获得多个输出,您可以在后续步骤中选择这些输出。