读取 rails 控制器中的 JSON 数组值

Read the JSON array value in the rails controller

我尝试通过 post 方法获取参数

POST /api/test HTTP/1.1
Host: localhost:3000
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 945ce038-4bf1-ed50-afcb-cc715cf3a3fc

{
    "service_requests": [{"service_id":2},{"service_id" : 3}]
}

在控制器中,我用一种方法进行了测试并像这样打印。但我无法打印这个。如何从这个 Json JSON 对象数组

打印 for each 或 for 循环中的所有值
def test
   render :html => params[:service_requests][0].service_id
end

请试试这个

     render :html => params[:service_requests].map{|s| s["service_id"]}