Azure Logic App使用range表达式初始化数组变量失败求助
问题解决:Logic Apps中用range初始化数组变量报错
问题描述
尝试用range表达式初始化数组变量,预期range返回整数数组,却收到BadRequest错误:
BadRequest
The variable 'temp1' of type 'Array' cannot be initialized or updated with value of type 'String'. The variable 'temp1' only supports values of types 'Array'.
涉及的初始化步骤代码:
{ "type": "InitializeVariable", "inputs": { "variables": [ { "name": "Test", "type": "array", "value": "@{range(0,10)}" } ] }, "runAfter": { "Compose_2": [ "Succeeded" ] } }
问题原因
在Logic Apps的JSON定义中,@{表达式}语法会将表达式执行结果强制转换为字符串类型,而非保留原有的数组类型,因此出现字符串赋值给数组变量的类型不匹配错误。
解决方法
去掉表达式外层的{},直接使用@range(0,10)作为变量的value值,这样Logic Apps会直接解析表达式并返回数组对象,而非字符串。
修正后的代码:
{ "type": "InitializeVariable", "inputs": { "variables": [ { "name": "Test", "type": "array", "value": "@range(0,10)" } ] }, "runAfter": { "Compose_2": [ "Succeeded" ] } }
内容的提问来源于stack exchange,提问作者Dean
相关产品推荐
相关产品推荐

