通过使用两个属性检查条件 - WSO2 ESB,从JSON过滤数据



以下是json文件:

    {
      "_id": "rezbase_v3",
      "_rev": "3-096e751caeeda12a8c30e28075a95e97",
      "exchangerate_data": [        
        {
          "buyingrate": 0.274725274725275,
          "sellingrate": 0.274725274725275,
          "buyingrateinverse": 3.64,
          "sellingrateinverse": 3.64,
          "basecurrency": {
            "currencyCode": "USD",
            "currencyName": "US dollar"
          },
          "quotecurrency": {
            "currencyCode": "QAR",
            "currencyName": "Qatari riyal"
          },
          "updateddate": 1491182700431,
          "basecurrencyname": "US dollar",
          "quotecurrencyname": "Qatari riyal"
        },
        {
          "buyingrate": 0.00681384573453257,
          "sellingrate": 0.00681384573453257,
          "buyingrateinverse": 146.76,
          "sellingrateinverse": 146.76,
          "basecurrency": {
            "currencyCode": "USD",
            "currencyName": "US dollar"
          },
          "quotecurrency": {
            "currencyCode": "LKR",
            "currencyName": "Sri Lankan rupee"
          },
          "updateddate": 1491182700431,
          "basecurrencyname": "US dollar",
          "quotecurrencyname": "Sri Lankan rupee"
        }
      ]
    }

,从文件中,我需要在基本货币/货币代码为usd的情况下过滤购买率,而quotecurrency/crurnerncode为lkr。

我尝试了以下表达式:

<property description="quote1" expression="//jsonObject/exchangerate_data[basecurrency/currencyCode='USD' and quotecurrency/currencyCode='LKR']/buyingrate/text()" name="quote1" scope="default" type="STRING"/>

我可以获得购买额度。

但是,当我将值作为属性并试图获得购买率时,它正在记录该值的确切表达式。

<property description="basecurrency" name="basecurrency" scope="default" type="STRING" value="USD"/>
<property description="quotecurrency" name="quotecurrency" scope="default" type="STRING" value="LKR"/>
<property name="apos" scope="default" type="STRING" value="'"/>
<property description="exchangeratePath" expression="fn:concat(get-property('exchangeratePath'),'//jsonObject/exchangerate_data[basecurrency/currencyCode=',get-property('apos'),get-property('basecurrency'),get-property('apos'),' and quotecurrency/currencyCode=',get-property('apos'),get-property('quotecurrency'),get-property('apos'),']/buyingrate/text()')" name="exchangeratePath" scope="default" type="STRING"/>
<log level="custom">
   <property expression="get-property('exchangeratePath')" name="exchangeratePath"/>
</log>

记录值:

[2018-04-27 08:50:41,314]  INFO - LogMediator exchangeratePath = //jsonObject/exchangerate_data[basecurrency/currencyCode='USD' and quotecurrency/currencyCode='LKR']/buyingrate/text()

我已经检查了此答案中提到的方式。

这是由:

解决的
<property description="exchangeratePath" expression="fn:concat(get-property('exchangeratePath'),'//jsonObject/exchangerate_data[basecurrency/currencyCode=',get-property('apos'),get-property('basecurrency'),get-property('apos'),' and quotecurrency/currencyCode=',get-property('apos'),get-property('quotecurrency'),get-property('apos'),']/buyingrate/text()')" name="exchangeratePath" scope="default" type="STRING"/>
<property description="exchangeRate" expression="evaluate($ctx:exchangeratePath)" name="exchangeRate" scope="default" type="STRING"/>

最新更新