gpt4 book ai didi

ruby - 如何在 Ruby 中将 JSON 转换为 XML?

转载 作者:数据小太阳 更新时间:2023-10-29 01:42:07 26 4
gpt4 key购买 nike

有什么方法可以在 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 的根参数。如果您不指定根,它会使用“哈希”一词作为根,这看起来不太好看。

关于ruby - 如何在 Ruby 中将 JSON 转换为 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4272410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com