2017-08-09 39 views
0

我有以下的JSON請求發佈數據工作正常。如何將json數組轉換爲xml數組以便發佈請求?

「客戶」=> { 「子域」=> 「測試」, 「名字」=> 「約翰」, 「姓氏」=> 「母鹿」, 「電子郵件」=>「john.doe @ example.com」, 「公司」=> 「樣本」, 「DEFAULT_LANGUAGE」=> 「EN」, 「active_modules」=> [ 「CMDB」, 「EVM」, 「ITIL」]}

我也爲我的服務器啓用了XML,因此也想回復XML發佈請求。我試圖將上面的JSON數據轉換爲XML,但並不像預期的那樣。

<customer> 
    <active_modules> 
     <element>cmdb</element> 
     <element>evm</element> 
     <element>itil</element> 
    </active_modules> 
    <company>Sample</company> 
    <default_language>en</default_language> 
    <email>[email protected]</email> 
    <firstname>john</firstname> 
    <lastname>doe</lastname> 
    <subdomain>Test</subdomain> 
</customer> 

問題是數組元素。我怎樣才能轉換這個數組元素傳遞完全相同的數據作爲JSON請求到服務器?

回答

0

對於一個數組,您需要多次傳遞相同的節點。

<customer> 
    <active_modules>cmdb</active_modules> 
    <active_modules>evm</active_modules> 
    <active_modules>itil</active_modules> 
    <company>Sample</company> 
    <default_language>en</default_language> 
    <email>[email protected]</email> 
    <firstname>john</firstname> 
    <lastname>doe</lastname> 
    <subdomain>Test</subdomain> 
</customer>