Power Automate流响应体换行符替换及Apply to each报错求助
问题解决方案
错误原因
- Apply to each循环仅用于遍历数组,你直接传入replace返回的字符串,不符合循环的输入要求,触发报错。
- 表达式中错误地将换行符写成了
'/n',实际需使用转义字符'\n',语法错误会导致替换逻辑失效。
解决步骤
- 删除当前的Apply to each循环——单字符串的替换操作完全不需要遍历循环。
- 在第二个API的请求体中,直接使用修正后的replace表达式:
replace(outputs('HTTP_call_to_the_Source')?['body'], '\n', '\r\n') - 验证逻辑:该表达式会将第一个API响应体中所有
\n换行符替换为\r\n,完全匹配第二个API的格式要求。
补充说明
你之前写的两次replace属于冗余操作,一次替换即可完成需求;同时需注意Power Automate中转义字符的写法,换行符必须用\n而非/n。
The execution of template action 'Apply_to_each_2' failed: the result of the evaluation of 'foreach' expression '@replace(body('HTTP_call_to_the_Source'), '/n', '/r/n')' is of type 'String'. The result must be a valid array.
内容的提问来源于stack exchange,提问作者cacharry
相关产品推荐
相关产品推荐

