且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Savon 将 XML 作为字符串返回,而不是散列

更新时间:2022-02-03 04:31:16

我能够得到想要的结果,但使用 本文档.这似乎是一个不太理想的方法,但我意识到最后一个元素是一个哈希数组.所以它是散列,散列,带有散列数组.无论如何,这对我有用.关于如何使这个不那么丑陋和笨重的建议将不胜感激.

I was able to get the desired results but parsing the Nori string(?) using this documentation. This seems like a less than ideal method, but I realized the last element is an array of hashes. So it's hash, of hashes, with an array of hashes. Anyway, here is what worked for me. Advice on how to make this less ugly and clunky would be appreciated.

response = soapClient.request(:get_sites_user_can_access) do
  soap.body = { :sessionid  => session[:login_response][:login_return],
                :eid        => user }
end

rep = response.to_hash[:get_sites_user_can_access_response][:get_sites_user_can_access_return]

hrep = Nori.parse(rep)

hrep[:list][:item].each { |item| pp item[:site_id] }