开发者

Passing boolean value in JSON

My setup: Rails 2.3.10, Ruby 1.8.7

This is a simple question but I want to pass a boolean value for a field in a JSON string that will be interpreted by Rails as boolean, e.g., what do I use for "a" below? Is it 0 or 1 or "true" or "false" or ?

{ 
  "a": ??,
  "b": [1,2,3...],
  "c": 3
} 

Is there another way to test for true or false in Ruby besides comparing it to true, e.g.,

a开发者_运维知识库 = params[:a]
if a == true


in JSON the value for true is.... true

edit:

a quick google search turned up this solution over on github. This will save you the trouble of making a JSON parser yourself, assuming that is your end goal.


Scott M is right on the JSON part. On the Rails end, I need to use this method to convert it into Rails boolean format

ActiveRecord::ConnectionAdapters::Column.value_to_boolean(params[:a])

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜