0
嘿家伙,所以我想构建一些基于表单提交的JSON。我的JSON需要是这样(截断为简单起见):Ruby/Rails嵌套哈希myhash [“key1”] [“childkey”] - NoMethodError
{"id":0,"creditCard":{"address":{"state":"AZ"}}}
基本上我试图做这样的:
json_hash = Hash.new
json_hash["id"] = 0
json_hash["creditCard"]["address"]["state"] = "test"
json_hash.to_json
但其引发此errror:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
在给出的例子中的第三行(深度嵌套的东西)。红宝石哈希像这样工作吗?或者我需要采取额外的步骤?