我已经使用WSO2 EI将JSON消息发送到了后端服务器。但是它发送了错误的JSON格式。我已经使用了WSO2EI-6.4.0进行此任务。我添加了我使用过的示例XML请求。
<jsonObject>
<checkInDate>2019-03-25</checkInDate>
<checkOutDate>2019-03-26</checkOutDate>
<cityCode>3086</cityCode>
<hotelCode />
<roomOccupancyList>
<jsonArray>
<?xml-multiple jsonElement?>
<jsonElement>
<childAges>0</childAges>
<numberOfAdults>1</numberOfAdults>
<numberOfChildren>0</numberOfChildren>
<roomNo>1</roomNo>
</jsonElement>
</jsonArray>
</roomOccupancyList>
</jsonObject>
,但我从ESB方面遵循JSON请求。一旦通过ESB服务发送消息。
{
"checkInDate": "2019-06-04",
"checkOutDate": "2019-06-05",
"cityCode": "1344",
"hotelCode": "",
"roomOccupancyList": {
"childAges": "0",
"numberOfAdults": "1",
"numberOfChildren": "0",
"roomNo": "1"
}
}
此" RoomoccupancyList "应具有JSONARRAY对象,默认情况下它显示为JSONOBJECT。如果我在此处添加了多个jsonelement,则显示为JSONARRAY。但是我什至还需要一个JSONELEMENT。您能帮我解决这个问题吗?我已经驳回了以上任务的链接。WSO2 DOC链接
JSON响应应加载以下格式。
{
"checkInDate": "2019-06-04",
"checkOutDate": "2019-06-05",
"cityCode": "1344",
"hotelCode": "",
"roomOccupancyList": [
{
"childAges": "0",
"numberOfAdults": "1",
"numberOfChildren": "0",
"roomNo": "1"
}
]
}
我已经使用了以下XSLT来实现此操作,并且它正在毫无问题。另外,您需要在Synapse.properties/esb_home/conf文件夹中添加以下属性。
synapse.json.to.xml.processing.instruction.enabled=true
这是您进一步参考的样本XSLT。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="/request">
<availabilityRequest>
<jsonObject>
<checkInDate>2019-03-25</checkInDate>
<checkOutDate>2019-03-26</checkOutDate>
<cityCode>3086</cityCode>
<xsl:variable name="roomCount" select="count(roomsInformation)" />
<xsl:for-each select="roomsInformation">
<xsl:if test="$roomCount = 1">
<xsl:processing-instruction name="xml-multiple"/>
</xsl:if>
<xsl:variable name="roomIndex" select="position()" />
<roomOccupancyList>
<jsonArray>
<childAges>0</childAges>
<numberOfAdults>1</numberOfAdults>
<numberOfChildren>1</numberOfChildren>
<roomNo><xsl:value-of select="$roomIndex" /></roomNo>
</jsonArray>
</roomOccupancyList>
<xsl:if test="$roomCount = 1">
<xsl:copy-of select="Objects"></xsl:copy-of>
</xsl:if>
</xsl:for-each>
</jsonObject>
</availabilityRequest>
</xsl:template>
</xsl:stylesheet>