简体   繁体   English

在Rails中关闭JSON键引用

[英]Turning off json key quoting in Rails

One of the features in Rails 2.3 was json key quoting. Rails 2.3的功能之一是json键引用。 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 ). 我想输出一种Google可视化API可以接受的json格式( http://code.google.com/apis/visualization/documentation/dev/implementing_data_source.html#examples )。 The keys don't have quotes. 键没有引号。

From the Rails release notes: 从Rails发行说明中:

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. 如果您在“ json.org”站点上查找规范,您会发现JSON结构中的所有键都必须是字符串,并且必须用双引号引起来。 Starting with Rails 2.3, we do the right thing here, even with numeric keys. 从Rails 2.3开始,即使使用数字键,我们在这里也做正确的事。

This might sound a little silly, but what I did was just modify the Rails' code. 这听起来可能有些愚蠢,但是我所做的只是修改Rails的代码。 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! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM