我的应用程序将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":""}]
如何在控制器中,我可以循环遍历每个记录并获得记录。id、记录。full_name等。
谢谢
你的问题基本上是我如何将这个JSON字符串序列化成一个ruby对象(哈希)。你可以调用contacts=JSON.parse(json_string)
,然后调用contacts[0].id
,等等。