2017-01-02 103 views
0

這是我的背景: 我有這樣的身體JSON:遍歷在WSO2 ESB陣列

{ 
    "delivery": [ 
     { 
      "note": "aaaaaa", 
      "method": "x" 
     }, 
     { 
      "note": "bbb", 
      "method": "y" 
     }, 
     { 
      "note": "ccc", 
      "method": "x" 
     } 
    ], 
    "partner": { 
      "zip": "a", 
      "country": "b", 
      "city": "c"   
    } 
} 

我需要遍歷交付陣列和創建對象(投遞物品+夥伴對象),然後撥打電話到端點。

例如,這第一個對象:

{ 
    "delivery": 
    { 
     "note": "aaaaaa", 
     "method": "x" 
    } 
    "partner": { 
      "zip": "a", 
      "country": "b", 
      "city": "c" 
    } 
} 

,然後撥打電話到端點

該操作將被重複X = array.lenght

我創建這個序列,但它不」 t work

<?xml version="1.0" encoding="UTF-8"?> 
<sequence name="tec_notif-expe_v1" xmlns="http://ws.apache.org/ns/synapse"> 
    <in>  
     <property name="RESPONSE" scope="default" value="true"/> 
     <property action="remove" name="NO_ENTITY_BODY" scope="axis2"/> 
     <header action="remove" name="To"/> 
     <property name="partner" expression="json-eval($.partner)" scope="default" /> 
     <!-- iterate over delivery--> 
     <iterate continueParent="true" expression="//delivery"> 
      <target sequence="anon"> 
       <sequence> 
        <property name="deliveryItem" expression="//delivery" /> 

        <script language="js"><![CDATA[ 
         var body = {}; 
         body.delivery = {}; 
         body.partner = {}; 
         body.delivery = mc.getProperty('deliveryItem'); 
         body.partner = mc.getProperty('partner'); 

         mc.setPayloadJSON(body); 
        ]]></script> 
        <call> 
         <endpoint key="update-eklem"/> 
        </call> 
       </sequence> 
      </target> 
     </iterate> 
     <send /> 
     <drop />  
    </in> 
</sequence> 

你有什麼建議嗎?

致以問候

回答

0

您是否在日誌中看到任何錯誤?嘗試在迭代之前和之後添加日誌語句,以查看您收到的內容以及xpath是否正確。

我已經做了嵌套的JSON數組一樣沒有任何問題,除了XPath的:-)

我收到的請求是這樣的。

{ 
    "jsonElement" : [{ 
     "val1" : "some Value", 
     "val2" : "some Value" 
     "array" : [{ 
      .... data 
      "arrayVal1" : "array Val1", 
      .... 
     }] 
    }] 
} 

在序列中,我添加了以下內容。

<iterate continueParent="true" expression="//jsonElement"> 
    .. get some values e.g. <property name="val1" expression="//val1/text()" scope="default" type="STRING"/> 
    <iterate expression="//array"> 
     <property name="arrayVal1" expression="//arrayVal1/text()" scope="default" type="STRING"/> 
     ..... 
    </iterate> 
</iterate>