如何处理 Savon Responses?

发布于 2024-11-13 17:31:20 字数 239 浏览 5 评论 0原文

我不明白那些更喜欢 Savon 而不是 Soap4r 的人。

如何获取 Savon 响应中返回对象的属性?使用soap4r,它就像调用吸气剂一样干净!

显然,在 Savon 中我需要显式解析响应并遍历 response_hash。这比soap4r 方法要糟糕得多。我是不是搞错了,还是Savon只是质量较差的soap4r?

编辑:这个问题是由于 savon 没有正确支持 multi_ref 响应,如答案评论中所述。

I do not understand the people who prefer Savon to Soap4r.

How can I get the attributes of the returned object in a Savon response? With soap4r it's as clean as invoking a getter!

Apparently, in Savon I need to explicitly parse the response and walk the response_hash. This is way worse than the soap4r approach. Am I getting something wrong, or is Savon just a worse-quality soap4r?

edit: this question was due to savon not properly supporting multi_ref responses, as stated in an answer comment.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡笑忘祈一世凡恋 2024-11-20 17:31:20

来自 https://github.com/raldred/savon/blob/ master/lib/savon/response.rb

  # You can also let Savon translate the SOAP response body to a Hash.
  #
  #   response.to_hash
  #   => { :findUserByIdResponse => {
  #   =>   :id => "123",
  #   =>   :username => "eve"
  #   =>   :active => true
  #   => }

所以你应该能够调用 hash[:object] 它将返回属性。

您不需要遍历响应对象,只需调用 to_hash 即可。

From https://github.com/raldred/savon/blob/master/lib/savon/response.rb

  # You can also let Savon translate the SOAP response body to a Hash.
  #
  #   response.to_hash
  #   => { :findUserByIdResponse => {
  #   =>   :id => "123",
  #   =>   :username => "eve"
  #   =>   :active => true
  #   => }

So you should be able to call hash[:object] which would return attribute.

You dont need to walk the response object just call to_hash.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文