我的应用将JSON对象发布回服务器,其结构如下:
contacts:[{"id":38,"full_name":"xxxxxxx","email":""},{"id":70,"full_name":"xxxxxxx","email":""},{"id":79,"full_name":"xxxx","email":""},{"id":22,"full_name":"xxxxxxx","email":""},{"id":48,"full_name":"xxxxxx","email":""},{"id":69,"full_name":"xxxxx","email":""}]
如何在控制器中,我可以遍历每个记录并获取record.id,record.full_name等。
由于
答案 0 :(得分:2)
您的问题基本上是如何将此JSON字符串序列化为ruby对象(哈希)。您可以致电contacts=JSON.parse(json_string)
,然后拨打contacts[0].id
,等等......