Power Automate调用认证流后无法解析JSON响应求助
Power Automate调用子认证流后Parse Json报错:InvalidJSON的解决方法
问题场景
拆分Power Automate流,将OAuth认证逻辑独立为子流,主流调用该子流获取access token后请求业务API。认证流单独执行正常,返回载荷为:
{ "straccesstoken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }
但主流中通过「Parse auth response」步骤解析时,触发以下错误:
InvalidJSON. The 'content' property of actions of type 'ParseJson' must be valid JSON. The provided value cannot be parsed: 'Unexpected character encountered while parsing value: A. Path '', line 0, position 0.'
调用认证流的响应头已包含Content-Type: application/json; charset=utf-8,仍无法解析。
原因分析
- 子流返回内容非纯JSON:认证流的返回配置错误,导致子流结束时返回的不是预期的JSON对象,而是Power Automate自动生成的执行描述文本(比如开头为"Action succeeded..."的字符串,对应报错中的字符'A')。
- 主流引用内容错误:Parse Json步骤的
Content参数未指向子流返回的JSON内容,而是误选了子流的执行元数据(如状态信息)。
修复方案
1. 修正认证流的返回配置
- 在认证流的最后添加「Respond to a PowerApp or flow」步骤:
- 设置输出参数:键填
straccesstoken,值选择之前解析得到的token变量; - 若需返回完整JSON对象,可设置一个参数,值为Parse Json后的完整结果对象。
- 设置输出参数:键填
- 确保认证流没有用其他方式返回内容(比如直接输出文本),必须通过「Respond」步骤返回结构化数据。
2. 主流中正确引用子流输出
- 无需Parse Json的简化方式:调用认证流后,直接通过表达式引用子流的输出参数,比如:
直接获取token值,跳过Parse Json步骤。body('Call_authentication_flow')?['straccesstoken'] - 保留Parse Json的方式:
- 先添加一个「Compose」步骤,将调用认证流的结果输出,确认内容是预期的纯JSON;
- 将Parse Json步骤的
Content字段设置为body('Call_authentication_flow')(若Compose显示正确JSON),或调整为子流返回的具体JSON属性。
3. 处理隐藏字符问题
若确认子流返回纯JSON但仍报错,可能存在UTF-8 BOM等隐藏字符:
- 在Parse Json前添加「Compose」步骤,使用表达式去除BOM:
replace(body('Call_authentication_flow'), '\ufeff', '') - 将Compose的结果传入Parse Json步骤的
Content字段。
内容的提问来源于stack exchange,提问作者mitch-NZ
相关产品推荐
相关产品推荐

