问题描述
我有来自两个不同端点的两个json,我需要串联以将其转换为单个有效json。我做到了,但是第一个WSO2 json将其作为字符串(firstjson)返回。我希望它全部是json。
FirsT JSON
window.appearance = NSAppearance(appearanceNamed: NSAppearance.Name.aqua,bundle: nil)
第二个JSON
[ { “ item1”:“ 123456”, “ item2”:“ 5678” }, { “ item1”:“ 8976”, “ item2”:“ abcd” } ]
XML API
{
"first": true,"second": {
"name": "manoj","age": "45"
},"third": {
"fourth": [
{
"class": "test12","salary": "123456"
},{
"class": "test23","salary": "15678"
}
],"fifth": "hello"
}
}
响应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>
我在哪里错了?
先谢谢大家
解决方法
好的,
我解决了这个问题,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>
还是谢谢大家:)