Rails,如何循环发送到服务器的 JSON 对象

发布于 2024-11-02 12:37:08 字数 394 浏览 0 评论 0原文

我的应用程序将一个 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 等。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城半夏 2024-11-09 12:37:08

您的问题基本上是如何将此 JSON 字符串序列化为 ruby​​ 对象(哈希)。您可以调用 contacts=JSON.parse(json_string) 然后您可以调用 contacts[0].id 等...

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文