关闭 Rails 中的 json 键引用

发布于 2024-07-17 05:27:14 字数 504 浏览 2 评论 0原文

Rails 2.3 中的功能之一是 json 键引用。 我想知道是否有一种简单的方法可以关闭关键引用或修改引用的完成方式(例如更改为单引号)。

我想输出 Google 可视化 API 可接受的 json 格式 (http://code.google.com/apis/visualization/documentation/dev/implementing_data_source.html#examples)。 键没有引号。

来自 Rails 发行说明:

如果您在“json.org”网站上查找规范,您会发现 JSON 结构中的所有键都必须是字符串,并且必须用双引号引起来。 从轨道开始 2.3,我们在这里做了正确的事情,即使使用数字键。

One of the features in Rails 2.3 was json key quoting. I was wondering if there was an easy way to turn the key quoting off or modify the way quoting is done (change to single quotes for example).

I'd like to output a json format that Google's Visualization API will accept (http://code.google.com/apis/visualization/documentation/dev/implementing_data_source.html#examples). The keys don't have quotes.

From the Rails release notes:

If you look up the spec on the “json.org” site, you’ll discover that all keys in a JSON structure must be strings, and they must be quoted with double quotes. Starting with Rails
2.3, we do the right thing here, even with numeric keys.

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

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

发布评论

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

评论(1

謌踐踏愛綪 2024-07-24 05:27:14

这听起来可能有点傻,但我所做的只是修改 Rails 的代码。 它既快又脏,每次升级时都必须重新应用它,但似乎没有更好的方法。 祝你好运!

This might sound a little silly, but what I did was just modify the Rails' code. It was quick and dirty, and you had to re-apply it at every upgrade, but there didn't seem to be a better way. Good luck!

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