简体   繁体   中英

How do I get the substring of a JSON output?

I want to render a simple JSON from an array.

array = ["valueid",true]
render :json=>array

which returns:

{"json":["valueid",true]}

but I don't want the JSON. The only part I want is:

["valueid",true]

Is there a simple way?

Yep:

get :index do
  [:id, 4].to_json
end

Better:

get :index, :provides => :json do
   my_array.to_json
end

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