簡體   English   中英

WSO2 Lopp 通過 Json 陣列

[英]WSO2 Lopp through Json array

這是我的輸入 Json:

如何獲取“值”字段並將其設置為屬性?

 [
        {
            "Name": "Утасны дугаар",
            "Value": "95252351",
            "ParameterName": "{xacparam01}",
            "IsRequired": "1",
            "MinLength": "5",
            "MaxLength": "10",
            "Type": "String"
        },
        {
            "Name": "dans",
            "Value": "99115544",
            "ParameterName": "{xacparam02}",
            "IsRequired": "1",
            "MinLength": "5",
            "MaxLength": "10",
            "Type": "String"
        },
        {
            "Name": "dfd",
            "Value": "88554455",
            "ParameterName": "{xacparam03}",
            "IsRequired": "1",
            "MinLength": "5",
            "MaxLength": "10",
            "Type": "String"
        }
    ]

當我循環通過 json 時,我只能獲得最后一次迭代

所需的 Output:

{
"val1" : "95252351",
"val2" : "99115544",
"val3" : "88554455"
}

無法為 JSON object 生成字段名稱。 您可以使用給定的代理獲得如下所示的 output。

output JSON

{
    "values": [
        95252351,
        99115544,
        88554455
    ]
}

代理服務

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="test2" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            <log level="full">
                <property name="log1" value="invoked"/>
            </log>
            <property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
            <property name="Content-Type" scope="transport" type="STRING" value="application/xml"/>
            <log level="full">
                <property name="log2" value="after conversion"/>
            </log>
            <foreach expression="//jsonArray/jsonElement" id="foreach">
                <sequence>
                    <payloadFactory media-type="xml">
                        <format>
                            <values xmlns="">$1</values>
                        </format>
                        <args>
                            <arg evaluator="xml" expression="//jsonElement/Value" literal="true"/>
                        </args>
                    </payloadFactory>
                </sequence>
            </foreach>
            <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
            <property name="Content-Type" scope="transport" type="STRING" value="application/json"/>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
</proxy>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM