Ruby Grape:如何将散列数组作为参数发送

时间:2018-05-04 18:54:40

标签: ruby-on-rails ruby swagger grape

我发送了一系列哈希值。

[{question_id: 1_id, answer:1_String},{question_id: 2_id, answer:2_String}]

我在我的API文件中使用了这段代码:

requires :profile_setting, type: Array[Hash], desc: "[{question_id: 1_id, answer: '1_String'},{question_id: 2_id, answer: '2_String'}]"

enter image description here

params:[{question_id: 1_id, answer:1_String},{question_id: 2_id, answer:2_String}]

回复:

{
  "error": "profile_setting is invalid"
}

如何发送多个哈希数组。

1 个答案:

答案 0 :(得分:1)

你的JSON错过了键和值的引号。

应该是

[{
"question_id": "1 _id",
"answer": "1 _String"
},
{
"question_id": "2 _id",
"answer": "2 _String"
}]