【问题标题】:I want to convert xml to json using apim policies我想使用 apim 策略将 xml 转换为 json
【发布时间】:2021-11-17 12:17:48
【问题描述】:

示例 xml 请求:

<env:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  <ns5:CreateCustomerProfileRequest>
    <ns5:SourceApplication>
      <ns3:ApplicationID>HYBRIS_01</ns3:ApplicationID>
      <ns3:ApplicationName>Hybris</ns3:ApplicationName>
    </ns5:SourceApplication>
    <ns5:CustomerProfile>
      <ns5:CustomerIdentification>
        <ns5:CustomerIDType>bill-to</ns5:CustomerIDType>
        <ns5:CustomerID>618a18b3f33fa4007f2e76be</ns5:CustomerID>
        <ns5:CustomerNumber/>
      </ns5:CustomerIdentification>
      <ns5:UserId>franlopue@icloud.com</ns5:UserId>
      <ns5:CustomerType>Customer</ns5:CustomerType>
      <ns5:CustomerAddressBook>
        <ns3:Email>
          <ns3:EmailAddress>franlopue@icloud.com</ns3:EmailAddress>
        </ns3:Email>
      </ns5:CustomerAddressBook>
      <ns5:CustomerName>
        <ns3:FirstName>Francisco</ns3:FirstName>
        <ns3:LastName>Lopez-puente</ns3:LastName>
      </ns5:CustomerName>
      <ns5:CustomerSleep>35</ns5:CustomerSleep>
      <ns5:ModifiedByName/>
      <ns5:BillToInd>false</ns5:BillToInd>
      <ns5:ShipToInd>false</ns5:ShipToInd>
    </ns5:CustomerProfile>
  </ns5:CreateCustomerProfileRequest>
</env:Body>

Json :

{"body": {
"ProcessName":"SC Account Registration Process",
            "SiebelMessage": {
            "IntObjectName": "SC EAI Contact",
            "MessageType": "Integration Object",
            "IntObjectFormat": "Siebel Hierarchical",
            "ListOfSC EAI Contact": {
                "Contact": 
                {
                    "Email Address": "test555@test.com",  
                    "First Name": "SRI",
                    "Last Name": "TEST",
                    "SC External Customer Id":"1234aew",
                    "Integration Id":"1234aew",
                    "Type":"CRM_Unqualified",
                    "SC Sleep ":"35"
 }}}}}

如何使用 apim 策略将上述 xml 转换为上述 json 格式。请让我知道我们可以使用什么来获取代码的确切格式。目前我想为此使用 azure azure apim 策略。

【问题讨论】:

标签: azure-api-management api-management apim


【解决方案1】:

根据@DeepDave-MT 的建议,基于MS DOC

将 xml 转换为 json,我们可以在我们的代码中使用以下代码示例 用于此的 azure apim 策略

政策声明

<xml-to-json  kind="javascript-friendly | direct"  apply="always | content-type-xml"  consider-accept-header="true | false"/>

然后尝试添加下面的例子进行转换

<policies>  <inbound>  <base />  </inbound>  <outbound>  <base />  <xml-to-json kind="direct" apply="always" consider-accept-header="false" />  </outbound>  </policies>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多