从base64编码的字符串中解析Azure Logic App中的JSON数组,以便在For_each中使用

时间:2016-08-03 16:02:32

标签: azure azure-servicebus-queues azure-logic-apps

我正在尝试遍历已编码为字符串的JSON数组,以便存储在队列中。但是,我收到以下错误消息:

  

{“code”:“ExpressionEvaluationFailed”,“message”:“执行   模板操作'For_each'失败:结果'[{\“Foo \”:\“Bar \”}]'的   对'foreach'动作表达的评价   '@ {json(decodeBase64(triggerBody()['ContentData']))}''无效   阵列。“}

以下是要解析的字符串: [{"Foo":"Bar"}]

JSON字符串不在数组中时,我没有遇到任何问题,例如: {"Foo":"Bar"}

当我不使用For_each时,这解析得很好。

如何让逻辑应用程序将其作为数组读取?

1 个答案:

答案 0 :(得分:10)

这里的问题是你正在使用字符串插值(其中表达式包装在@ {...}中),其值为数组的字符串表示形式。因此,对'foreach'表达式的评估失败了。

你想要表达式 def listwrite(output_file,thelist): for item in thelist: item.encode('utf-8') output_file.write("%s\n" % item)