25
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

XMLをJSONに変換する

Posted at

例えば http://hoge.com/data.xml というXMLを返すAPIがあったとして、ここからJSONデータに変換したいなら以下のコード。
ただしActiveSupportが必要なので、Rails以外の環境では、ActiveSupportを別途インストールすること。

require 'active_support/core_ext'
require 'open-uri'

hash = Hash.from_xml open('http://hoge.com/ext/data.xml').read
json = hash.to_json

ActiveSupportはこういったメソッド以外にも便利なものを大量に揃えている。

25
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?