PowerApps自定义连接器调用翻译API时JSON解析错误求助
问题排查:PowerApps自定义连接器JSON解析错误
问题概述
在PowerApps中创建了调用语言翻译API的自定义连接器,连接器返回的响应符合预期,但调用时触发错误:"JSON parsing error, expected 'string' but got 'array'"
请求示例
{ "pipelineTasks": [ { "taskType": "asr", "config": { "language": { "sourceLanguage": "hi" }, "serviceId": "", "audioFormat": "flac", "samplingRate": 8000 } }, { "taskType": "translation", "config": { "language": { "sourceLanguage": "hi", "targetLanguage": "en" }, "serviceId": "" } }, { "taskType": "tts", "config": { "language": { "sourceLanguage": "en" }, "serviceId": "", "gender": "female", "samplingRate": 8000 } } ], "inputData": { "audio": [ { "audioContent": "//base64 string" } ] } }
响应示例
{ "pipelineResponse": [ { "taskType": "asr", "config": { "serviceId": "", "language": { "sourceLanguage": "hi", "sourceScriptCode": "" }, "audioFormat": "flac", "encoding": null, "samplingRate": 8000, "postProcessors": null }, "output": [ { "source": "मेरा नाम महीर है और मैं भाषा वर्ष यूज़ कर रहा हूँ" } ], "audio": null }, { "taskType": "translation", "config": null, "output": [ { "source": "मेरा नाम महीर है और मैं भाषा वर्ष यूज़ कर रहा हूँ", "target": "My name is Maher and I'm using the language Year" } ], "audio": null }, { "taskType": "tts", "config": { "language": { "sourceLanguage": "en", "sourceScriptCode": "" }, "audioFormat": "wav", "encoding": "base64", "samplingRate": 8000, "postProcessors": null }, "output": null, "audio": [ { "audioContent": "//base64", "audioUri": null } ] } ] }
问题根源
查看提供的Swagger定义,发现pipelineResponse.items.properties.output的类型被错误定义为string,但实际响应中output是数组类型(包含对象元素),部分场景下还会返回null,类型不匹配导致PowerApps解析JSON时出错。
原Swagger中错误的定义片段:
output: type: string description: output
修复方案
修改Swagger定义中output字段的类型,使其匹配实际响应结构:
output: type: array items: type: object properties: source: type: string description: Source text target: type: string description: Translated text x-nullable: true description: output
说明:
- 将
type从string改为array,并定义数组元素的结构(包含source和可选的target字段) - 添加
x-nullable: true(Swagger 2.0中用于标记字段可返回null),适配tts任务中output为null的场景
修改后重新导入Swagger定义到PowerApps自定义连接器,即可解决JSON解析错误。
内容的提问来源于stack exchange,提问作者partha buragohain
相关产品推荐
相关产品推荐

