2015-01-26 90 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