Ruby如何将JSON转换为XML?
发布时间:2020-12-16 22:30:55 所属栏目:百科 来源:网络整理
导读:有没有办法在 Ruby中将JSON转换为XML? 解决方法 require 'active_support' #for to_xml() 'gem install activesupport' use the 2.3 branchrequire 'json' #part of ruby 1.9 but otherwise 'gem install json'my_json = "{"test":"b"}"my_xml = JSON.p
有没有办法在
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的根参数.如果你没有指定一个根,它将使用“哈希”这个词作为根,这不是很好看. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |