An external web service is sending json or xml towards my app. What would be the best way to consume this data? Is there a built-in library in Rails or Ruby to do this or do I need to use a gem for this?
For parsing json, you can use rails' method ActiveSupport::JSON.decode directly in your controller code. For what concerns XML parsing instead, you can choose between rexml (included in the ruby Standard Library), hapricot and libxml-ruby (available via ruby gem).
The choice is ultimately a matter of taste and performance. This benchmark claims that libxml-ruby is the fastest one, though it requires a few other libraries.
if it is a web service you query as a source of data, consider making an ActiveResource here is a railscast of the basics
Try nokogiri .
There's a good explanation of how to use it here:
http://www.robertsosinski.com/2008/12/08/scraping-pages-made-easy-with-ruby-and-nokogiri/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.