[英]Concatenate two JSON responses in wso2 esb
我有来自两个不同端点的两个 json,我需要连接以将其转换为单个有效的 json。 我做到了,但是第一个 WSO2 json 将它作为字符串 (firstjson) 返回。 我希望它全部是一个 json。
第一个 JSON
{
"first": true,
"second": {
"name": "manoj",
"age": "45"
},
"third": {
"fourth": [
{
"class": "test12",
"salary": "123456"
},
{
"class": "test23",
"salary": "15678"
}
],
"fifth": "hello"
}
}
第二个 JSON
[ { "item1": "123456", "item2": "5678" }, { "item1": "8976", "item2": "abcd" } ]
XML API
<api context="/concat" name="concat" xmlns="http://ws.apache.org/ns/synapse"> <resource methods="GET" url-mapping="/concatenare"> <inSequence> <call> <endpoint> <http method="get" uri-template="http://www.mocky.io/v2/56b2d88c13000057518945d4"> <suspendOnFailure> <initialDuration>-1</initialDuration> <progressionFactor>1</progressionFactor> </suspendOnFailure> <markForSuspension> <retriesBeforeSuspension>0</retriesBeforeSuspension> </markForSuspension> </http> </endpoint> </call> <enrich> <source clone="false" type="body"/> <target property="first-json" type="property"/> </enrich> <log level="custom"> <property expression="get-property('first-json')" name="First json"/> </log> <call> <endpoint> <http method="get" uri-template="http://www.mocky.io/v2/56b2d87d1300007c518945d3"> <suspendOnFailure> <initialDuration>-1</initialDuration> <progressionFactor>1</progressionFactor> </suspendOnFailure> <markForSuspension> <retriesBeforeSuspension>0</retriesBeforeSuspension> </markForSuspension> </http> </endpoint> </call> <log level="custom"> <property expression="get-property('first-json')" name="*********BEFOREEEEEEEE"/> </log> <!-- <enrich> <source clone="false" property="first-json" type="property"/> <target type="body"/> </enrich> --> <payloadFactory media-type="xml"> <format> <completeJson xmlns=""> <firstjson>$1</firstjson> <secondjson>$2</secondjson> </completeJson> </format> <args> <arg evaluator="xml" expression="get-property('first-json')"/> <arg evaluator="xml" expression="$body"/> </args> </payloadFactory> <property name="messageType" scope="axis2" type="STRING" value="application/json"/> <send/> </inSequence> <outSequence/> <faultSequence/> </resource> </api>
响应接口
{ "completeJson": { "firstjson": "{\\"first\\":true,\\"second\\":{\\"name\\":\\"manoj\\",\\"age\\":\\"45\\"},\\"third\\":{\\"fourth\\":[{\\"class\\":\\"test12\\",\\"salary\\":\\"123456\\"},{\\"class\\":\\"test23\\",\\"salary\\":\\"15678\\"}],\\"fifth\\":\\"hello\\"}}", "secondjson": { "Body": [ { "item1": 123456, "item2": 5678 }, { "item1": 8976, "item2": "abcd" } ] } } }
我哪里错了?
提前谢谢各位
好,朋友们,
我解决了它,我错了payloadFactory,它的格式必须是json类型。
<payloadFactory media-type="json">
<format>
{
"completeJson" : {
"firstjson" : $1,
"secondjson" : $2
}}
</format>
<args>
<arg expression="get-property('first-json')" />
<arg expression="$body" />
</args>
</payloadFactory>
无论如何,谢谢你们:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.