How do I serialize hash format:
I have the following data:
[{"uid"=>"12406664"}, {"uid"=>"13715056"}, {"uid"=>"20911274"}, {"uid"=>"20921750"}, {"uid"=>"144901695"}, {"uid"=>"200002261"}, {"uid"=>"583131545"}, {"uid"=>"584667098"开发者_Python百科}, {"uid"=>"585043552"}, {"uid"=>"593713530"}, {"uid"=>"645734146"}, {"uid"=>"649596998"}, {"uid"=>"663955553"}, {"uid"=>"698033741"}, {"uid"=>"1024899231"}, {"uid"=>"1032611215"}, {"uid"=>"1076202442"}, {"uid"=>"1168728549"}, {"uid"=>"1283882122"}, {"uid"=>"1296965460"}, {"uid"=>"1417999220"}, {"uid"=>"1420197620"}, {"uid"=>"1455766774"}, {"uid"=>"1479820827"}, {"uid"=>"1568075339"}, {"uid"=>"100000804563736"}, {"uid"=>"100001055926570"}, {"uid"=>"100001633945205"}]
How do I store this data using Ruby on Rails? I'd like to keep the data accesable, where
>> x[1]
=> {"uid"=>"13715056"}
Currently I'm using a postgreSQL heroku server, I have the User.user_id column serialized as a Hash and the data is a mess:
"[{\"uid\"=>\"12406664\"}, {\"uid\"=>\"13715056\"}, {\"uid\"=>\"20911274\"}, {\"uid\"=>\"20921750\"}, {\"uid\"=>\"144901695\"}, {\"uid\"=>\"200002261\"}, {\"uid\"=>\"583131545\"}, {\"uid\"=>\"584667098\"}, {\"uid\"=>\"585043552\"}, {\"uid\"=>\"593713530\"}, {\"uid\"=>\"645734146\"}, {\"uid\"=>\"649596998\"}, {\"uid\"=>\"663955553\"}, {\"uid\"=>\"698033741\"}, {\"uid\"=>\"1024899231\"}, {\"uid\"=>\"1032611215\"}, {\"uid\"=>\"1076202442\"}, {\"uid\"=>\"1168728549\"}, {\"uid\"=>\"1283882122\"}, {\"uid\"=>\"1296965460\"}, {\"uid\"=>\"1417999220\"}, {\"uid\"=>\"1420197620\"}, {\"uid\"=>\"1455766774\"}, {\"uid\"=>\"1479820827\"}, {\"uid\"=>\"1568075339\"}, {\"uid\"=>\"100000804563736\"}, {\"uid\"=>\"100001055926570\"}, {\"uid\"=>\"100001633945205\"}]"
>> User.last.uid.last
=> "]"
How can I correct this?
Thank you!
you can serialize as you wish: Hash
, Array
, custom class... you're quite free.
As of your expectations, serialize as an Array
.
精彩评论