gpt4 book ai didi

ruby-on-rails - 无方法错误 : undefined method `from_json' for "{}":String

转载 作者:太空宇宙 更新时间:2023-11-03 17:26:48 25 4
gpt4 key购买 nike

当我在我的项目中加载 Rails 控制台时,我可以这样做:

{}.to_json

但是我不能这样做:

"{}".from_json

即使我首先需要 json gem,它也不起作用。 from_json 方法是否存在?

最佳答案

没有。 from_json 不存在。如果您想从 JSON 字符串中获取 Ruby 哈希,可以使用 JSON#parse 方法。示例如下:

json = JSON.parse("{\"hello\":\"world\"}")

以上返回 {"hello"=>"world"}

关于ruby-on-rails - 无方法错误 : undefined method `from_json' for "{}":String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6847550/

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