[英]restrict backslash while convering to JSON from ruby
I am working on a ruby API's.This API fetching db value and converted into a JSON format.我正在研究 ruby API。这个 API 获取 db 值并转换为 JSON 格式。
Below code used to fetch data from db and converted into JSON format下面的代码用于从数据库中获取数据并转换为 JSON 格式
def get_data
response= data.select(:xx, :xxx, :xxx, :xxx ).where(:id => xxx1,:xx1 => xx1)
if response.empty?
respond_to do |format|
msg = {:message => "No records found"}
format.json { render :json => msg }
end
else
respond_to do |format|
format.json { render json: response.to_json }
end
end
end
Now am getting the response like below现在得到如下响应
How can i remove the slash from the response?如何从响应中删除斜杠? Thanks in advance.
提前致谢。
Note: I was tested this API's from POSTMAN
注意:我从
POSTMAN
测试了这个 API
Executed following solutions but the result was same执行了以下解决方案,但结果相同
use as_json
instead of to_json
使用
as_json
而不是to_json
removed .to_json
删除
.to_json
I don't think you can use the variable response
in a controller action.我认为您不能在 controller 操作中使用可变
response
。
It is already used by Rails: https://guides.rubyonrails.org/action_controller_overview.html#the-response-object它已经被 Rails 使用: https://guides.rubyonrails.org/action_controller_overview.html#the-response-object
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.