开发者

Rails, how to loop through a JSON object posted to the server

my app is posting a JSON object back to the server that is structured like so:

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":""}]

How in the controller, can I loop through each of the records and get the record.id, record.full_name etc.

Thanks


Your question is basically how do I serialize this JSON string into a ruby object (hash). You would call contacts=JSON.parse(json_string) you can then call contacts[0].id, etc...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜