Ruby JSON parse changes Hash keys

前端 未结 6 941
孤城傲影
孤城傲影 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:53

    1. Use ActiveSupport::JSON.decode, it will allow you to swap json parsers easier
    2. Use ActiveSupport::JSON.decode(my_json, symbolize_names: true)

    This will recursively symbolize all keys in the hash.

    (confirmed on ruby 2.0)

提交回复
热议问题