简体   繁体   English

在Ruby on Rails中,如何呈现JSON?

[英]In Ruby on Rails, how to render JSON?

I tried the following to respond to AJAX and it works (in HAML): 我尝试了以下方法来响应AJAX,并且它可以工作(在HAML中):

  - response.content_type = "application/json"
  = render :text => array_data.to_json

but

  - response.content_type = "application/json"
  = render :json => array_data.to_json

doesn't work. 不起作用。 I thought I could use 我以为我可以用

  = render :text => array_data.to_json

instead of the first 2 lines at the top? 而不是顶部的前2行?

= render :json => @object 

(您不需要使用.to_json方法)

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

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