简体   繁体   中英

Turning off json key quoting in Rails

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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