在逻辑应用程序参数函数中解析服务总线队列消息

Parsing Service Bus Queue message in Logic App parameter function

当我尝试使用触发我的逻辑应用程序的服务总线消息中的数据时,我的 SharePoint Get-Item 操作收到错误(内部 xml 已省略):

Unable to process template language expressions in action 'Get_items' inputs at line '1' and column '1641': 'The template language function 'json' parameter is not valid. The provided value '<?xml version="1.0" encoding="utf-8"?> <Projektaufgabe id="b92d6817-694e-e611-80ca-005056a5e651" messagename="Update"> ... </Projektaufgabe>' cannot be parsed: 'Unexpected character encountered while parsing value: . Path '', line 0, position 0.'.

解码后的消息 xml 看起来没问题,即使在错误消息中引用也是如此。

收到的队列消息正文似乎没问题 - 只有 ContentType 为空: (内容数据被截断)

{
  "ContentData": "77u/PD94bWwgdmVyc2lvbj0iMS4wIiBl...=",
  "ContentType": "",
  "ContentTransferEncoding": "Base64",
  "Properties": {
    "DeliveryCount": "1",
    "EnqueuedSequenceNumber": "20000001",
    "EnqueuedTimeUtc": "2016-07-29T09:03:40Z",
    "ExpiresAtUtc": "2016-08-12T09:03:40Z",
    "LockedUntilUtc": "2016-07-29T09:04:10Z",
    "LockToken": "67796ed8-a9f0-4f6a-952b-ccf4eda00071",
    "MessageId": "f3ac2ce4e7b6417386611f6817bf5da1",
    "ScheduledEnqueueTimeUtc": "0001-01-01T00:00:00Z",
    "SequenceNumber": "31806672388304129",
    "Size": "1989",
    "State": "Active",
    "TimeToLive": "12096000000000"
  },
  "MessageId": "f3ac2ce4e7b6417386611f6817bf5da1",
  "To": null,
  "ReplyTo": null,
  "ReplyToSessionId": null,
  "Label": null,
  "ScheduledEnqueueTimeUtc": "0001-01-01T00:00:00Z",
  "SessionId": null,
  "CorrelationId": null,
  "TimeToLive": "12096000000000"

}

SharePoint Get-Item OData 筛选器的解析函数如下所示:

@{json(base64ToString(triggerBody().ContentData)).Projektaufgabe.id}

我已经尝试过将解码和转换为字符串分开:

@{json(string(decodeBase64(triggerBody().ContentData))).Projektaufgabe.id}

由于解码消息似乎是一个问题,我认为从服务总线队列接收 json 消息而不是 xml 消息不会有多大帮助。

据我所知,您正在尝试将 xml 转换为 json。您非常接近-唯一的问题是@json() 期望

  1. 一个 string 是一个有效的 JSON 对象
  2. 要转换为 JSON
  3. application/xml 对象

在这里,@base64toString() 正在转换为字符串,但您确实需要让@json() 知道这是#2 而不是#1,因此将表达式更改为此应该有效:

@{json(xml(base64toBinary(triggerBody()[contentdata])))[foo]}

告诉我