有没有办法在
Ruby中将JSON转换为XML?
解决方法
- require 'active_support' #for to_xml() 'gem install activesupport' use the 2.3 branch
- require 'json' #part of ruby 1.9 but otherwise 'gem install json'
- my_json = "{\"test\":\"b\"}"
- my_xml = JSON.parse(my_json).to_xml(:root => :my_root)
还要注意to_xml的根参数.如果你没有指定一个根,它将使用“哈希”这个词作为根,这不是很好看.