如何在Power Automate中格式化这个对象/数组?
解决方案
我正在使用一个返回格式极其糟糕、我似乎无法使用的API。我只需要以编程方式把这样的格式
{
"987654321": {
"title": "Item One",
"amount": 60,
"id": "987654321"
},
"876543210": {
"title": "Item Two",
"amount": null,
"id": "876543210"
}
}
转换为这样的格式
{
{
"title": "Item One",
"amount": 60,
"id": "987654321"
},
{
"title": "Item Two",
"amount": null,
"id": "876543210"
}
}
结果需要能够用于类似Select(选择)动作或Apply to Each(逐项应用)等操作。我愿意尝试任何涉及原生Power Automate函数与功能的建议,以及涉及Office Scripts的方案。为了实现这看似简单的转换,我已经花了太多时间,任何帮助都将不胜感激。
对于需要以这种方式获得帮助的其他人,我在另一篇帖子中找到了由用户Skin提供的一个解决方案。 逻辑应用(Power Automate)从Planner计划中的任务提取清单项
我没有使用那条提到的付费连接器,但XML选项对我确实有用。下面是他们所做工作的要点:
假设初始数据保存在名为Compose_Data的 Compose步骤中。
Compose xpath results
Inputs: xpath(xml(json(concat('{ "results": ', outputs('Compose_Data'), '}'))), '//results/*')
Select results ids
From: outputs('Compose_xpath_results')
Map key: id (or whatever you want to call it)
Map value: replace(replace(xpath(xml(base64ToString(item()['$content'])), 'name(/*)'), '_x003', ''), '_', '')
Apply to each result
From: body('Select_results_ids')
//now you can grab whatever fields you have
Compose title
Inputs: outputs('Compose_Data')?\[items('Apply_to_each_result')?\['id'\]\]?\['title'\]
Compose id
Inputs: outputs('Compose_Data')?\[items('Apply_to_each_result')?\['id'\]\]?\['id'\]
//you can either append this info to an array variable at this point
//or just do what you would do with the array from inside this apply to each if you don't need to filter or anything
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。