英文:
Azure Data Factory ForEach Parsing QueueMessageList
问题
我正在使用以下动态表达式在ForEach项目中将QueueMessageList中的QueueMessageText提供给后续的管道过程:
@json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage
当QueueMessageList中有多个QueueMessageText时,这个方法运行良好,但当只有一个QueueMessageText时,会出现以下错误信息:
函数'length'期望其参数为数组或字符串。提供的值为'Object'类型
这是单个QuoteMessageText的XML示例:
"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<QueueMessagesList>
<QueueMessage>
<MessageId>test1</MessageId>
<InsertionTime>Thu, 15 Jun 2023 04:21:06 GMT</InsertionTime>
<ExpirationTime>Thu, 22 Jun 2023 04:21:06 GMT</ExpirationTime>
<PopReceipt>popreceipt1</PopReceipt>
<TimeNextVisible>Thu, 15 Jun 2023 04:22:41 GMT</TimeNextVisible>
<DequeueCount>2</DequeueCount>
<MessageText>{"sample":"test.txt"}</MessageText>
</QueueMessage>
</QueueMessagesList>"
而这是包含多个QuoteMessageText的XML示例:
"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<QueueMessagesList>
<QueueMessage>
<MessageId>test1</MessageId>
<InsertionTime>Thu, 15 Jun 2023 04:21:06 GMT</InsertionTime>
<ExpirationTime>Thu, 22 Jun 2023 04:21:06 GMT</ExpirationTime>
<PopReceipt>pop1</PopReceipt>
<TimeNextVisible>Thu, 15 Jun 2023 06:14:57 GMT</TimeNextVisible>
<DequeueCount>5</DequeueCount>
<MessageText>{"sample":"test.txt"}</MessageText>
</QueueMessage>
<QueueMessage>
<MessageId>ctest2</MessageId>
<InsertionTime>Thu, 15 Jun 2023 06:13:39 GMT</InsertionTime>
<ExpirationTime>Thu, 22 Jun 2023 06:13:39 GMT</ExpirationTime>
<pop2</PopReceipt>
<TimeNextVisible>Thu, 15 Jun 2023 06:14:57 GMT</TimeNextVisible>
<DequeueCount>1</DequeueCount>
<MessageText>{"sample":"test2.txt"}</MessageText>
</QueueMessage>
</QueueMessagesList>"
我理解当将XML转换为JSON时,具有多个QueueMessageText的XML会创建一个QueueMessage列表,而只有一个QueueMessageText的XML会创建一个QueueMessageText字典。请告诉我如何修改ForEach Activity的表达式,因为我无法更改QueueMessageList的输出。谢谢!
英文:
I am using the dynamic expression below in ForEach Items to feed QueueMessageText from a QueueMessageList into subsequent pipeline process
@json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage
This works well when there are more than 1 QueueMessageText within the QueueMessageList but fails when there is only 1 QueueMessageText with the following error message:
> The function 'length' expects its parameter to be an array or a string. The provided value is of type 'Object'
These is the xml for single QuoteMessageText:
"
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<QueueMessagesList>
<QueueMessage>
<MessageId>test1</MessageId>
<InsertionTime>Thu, 15 Jun 2023 04:21:06 GMT</InsertionTime>
<ExpirationTime>Thu, 22 Jun 2023 04:21:06 GMT</ExpirationTime>
<PopReceipt>popreceipt1</PopReceipt>
<TimeNextVisible>Thu, 15 Jun 2023 04:22:41 GMT</TimeNextVisible>
<DequeueCount>2</DequeueCount>
<MessageText>{\"sample\":\"test.txt\"}</MessageText>
</QueueMessage>
</QueueMessagesList>"
And this is the xml for multiple QuoteMessageText within 1 list:
"
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<QueueMessagesList>
<QueueMessage>
<MessageId>test1</MessageId>
<InsertionTime>Thu, 15 Jun 2023 04:21:06 GMT</InsertionTime>
<ExpirationTime>Thu, 22 Jun 2023 04:21:06 GMT</ExpirationTime>
<PopReceipt>pop1</PopReceipt>
<TimeNextVisible>Thu, 15 Jun 2023 06:14:57 GMT</TimeNextVisible>
<DequeueCount>5</DequeueCount>
<MessageText>{\"sample\":\"test.txt\"}</MessageText>
</QueueMessage>
<QueueMessage>
<MessageId>ctest2</MessageId>
<InsertionTime>Thu, 15 Jun 2023 06:13:39 GMT</InsertionTime>
<ExpirationTime>Thu, 22 Jun 2023 06:13:39 GMT</ExpirationTime>
<pop2</PopReceipt>
<TimeNextVisible>Thu, 15 Jun 2023 06:14:57 GMT</TimeNextVisible>
<DequeueCount>1</DequeueCount>
<MessageText>{\"sample\":\"test2.txt\"}</MessageText>
</QueueMessage>
</QueueMessagesList>"
I understand that when i convert the XML to JSON, XML with Multiple QueueMessageText will create a QueueMessage list while XML with single QueueMessageText will create a QueueMessageText dictionary.
Please help me with a suggestion on how to modify the expression for the ForEach Activity as i cannot change the QueueMessageList output.
Thank you
答案1
得分: 0
我已将我的表达修改如下:
@array(json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage)
现在似乎可以工作。
英文:
I have modified my expression as follows:
@array(json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage)
It seems to work now.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论