【问题标题】:WSO2 Lopp through Json arrayWSO2循环遍历Json数组
【发布时间】:2019-11-20 08:14:01
【问题描述】:

这是我的输入 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时,我只能得到最后一次迭代

期望的输出:

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

【问题讨论】:

    标签: wso2 wso2esb wso2-am wso2carbon wso2ei


    【解决方案1】:

    无法为 JSON 对象生成字段名称。您可以使用给定的代理获得如下输出。

    输出 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      • 2015-07-22
      • 2013-08-16
      • 2011-06-11
      • 2013-02-06
      • 1970-01-01
      相关资源
      最近更新 更多