[英]restrict backslash while convering to JSON from ruby
我正在研究 ruby API。這個 API 獲取 db 值並轉換為 JSON 格式。
下面的代碼用於從數據庫中獲取數據並轉換為 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
現在得到如下響應
如何從響應中刪除斜杠? 提前致謝。
注意:我從POSTMAN
測試了這個 API
執行了以下解決方案,但結果相同
使用as_json
而不是to_json
刪除.to_json
我認為您不能在 controller 操作中使用可變response
。
它已經被 Rails 使用: https://guides.rubyonrails.org/action_controller_overview.html#the-response-object
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.