Ruby JSON parse changes Hash keys

前端 未结 6 933
孤城傲影
孤城傲影 2020-12-24 00:36

Lets say I have this Hash:

{
  :info => [
    {
        :from => \"Ryan Bates\",
        :message => \"sup bra\",
        :time => \"04:35 AM\"
          


        
6条回答
  •  不知归路
    2020-12-24 00:56

    You can't use that option like this

    ActiveSupport::JSON.decode(str_json, symbolize_names: true)

    In Rails 4.1 or later, ActiveSupport::JSON.decode no longer accepts an options hash for MultiJSON. MultiJSON reached its end of life and has been removed.

    You can use symbolize_keys to handle it. Warning: It works only for JSON strings parsed to hash.

    ActiveSupport::JSON.decode(str_json).symbolize_keys
    

提交回复
热议问题