我目前遇到了与以下线程中描述的问题类似的问题,确实需要一些帮助 -
我已经实现了确切的解决方案,但模板仍然无法读取值数组。
这是我的转换代码。
<json-to-xml apply="always" consider-accept-header="true" parse-date="true" />
<set-body template="liquid">
<soapenv:Envelope >
<soapenv:Body>
<Create xmlns="http://siebel.com/WebService">
<SharedList>
{% for item in body.sharedList.contact %}
<contact>
{% if item.userId %}
<UserId>{{item.userId}}</UserId>
{% else %}
<UserId>Empty</UserId>
{% endif %}
</contact>
{% endfor %}
</SharedList>
<AssetNum>{{body.Document.AssetNum}}</AssetNum>
</CreateSR_Input>
</soapenv:Body>
</soapenv:Envelope>
</set-body>
<!-- Set Content-Type header to XML -->
<set-header name="Content-Type" exists-action="override">
<value>application/xml</value>
</set-header>
我很感激任何建议。
这是示例有效负载。
{
"assetNum": "",
"sharedList": {
"contact": [
{
"userId": "spokuri"
}
]
}
}
您需要修改策略并将
Content-Type
添加到 application/json
,然后按照@Markus Meyer 在 SO 中的建议开始液体转换。
<policies>
<inbound>
<base />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body template="liquid">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Create xmlns="http://siebel.com/WebService">
<SharedList>
{% for item in body.sharedList.contact %}
<contact>
{% if item.userId %}
<UserId>{{item.userId}}</UserId>
{% else %}
<UserId>Empty</UserId>
{% endif %}
</contact>
{% endfor %}
</SharedList>
<AssetNum>{{body.Document.AssetNum}}</AssetNum>
</Create>
</soapenv:Body>
</soapenv:Envelope>
</set-body>
<set-header name="Content-Type" exists-action="override">
<value>application/xml</value>
</set-header>
</inbound>
</policies>
这会给你预期的回应。