json坏格式使用板Ruby

时间:2018-01-03 10:40:33

标签: json ruby

当我想用一块电路板时,我遇到了json格式的问题。 在我的json文件中,每个信息都有双括号,而我应该只有括号,是否可以删除其中一个?

代码:

elsif (params[:which] == "BigSize")
  res= []
  #   PrintType.where("width > 70").where("width <= 120").where("height > 118.9").where("height <= 150").pluck('DISTINCT artwork_id')
  big = PrintType.where("width > 70").where("width <= 120").where("height > 118.9").where("height <= 150").pluck('DISTINCT artwork_id')
  res << [big]
  render :json => res.to_json(include: { :images => { :except => :img_orig } })

结果:here

1 个答案:

答案 0 :(得分:0)

您正在将数组推送到数组res << [big]中 要停止创建两个括号,只需编写res << big,或者如果出于其他原因需要将res展平,然后再将其转换为json