2015-01-26 86 views
1

我正在使用Ruby Savon,並且我必須創建一個包含具有屬性的數組的請求。 我的問題是我如何在每個子數組中添加一個屬性。如何使用savon嵌套數組屬性!哈希?

<persons> 
    <person id=1> 
     <firstName>JOHN</firstName>     
    </person> 
    <person id=2> 
     <firstName>ANNIE</firstName> 
    </person> 
    </persons> 

我試着把屬性放到一個沒有成功的數組中。

{ 
    persons: { 
    person: [ { firstName: "JOHN"}, { firstName: "ANNIE" } ], 
    :attributes! => { :person=> [ { id: "1" }, { id: "2" } ] } 
    } 
}.to_soap_xml 

回答

4
{ 
    persons: { 
     person: [ { firstName: "JOHN", :@id => 1}, { firstName: "ANNIE", :@id => 2 } ] 
    } 
} 
+0

您手提包救了我們!謝謝。對這個在savon這個難解問題缺乏記錄感到有些遺憾。 – groky 2015-11-26 04:22:09

+0

很高興它幫助groky! – ConfusedUser 2015-11-26 04:53:03