rails json发布为哈希而不是数组

时间:2013-09-11 18:51:45

标签: ruby-on-rails ruby json

我遇到了一个关于ROR动作的ajax帖子的问题(从一个服务器到另一个服务器)。基本上,这个要求:

post_json = { "stuff": [{"1" => "foo"}] };

$.ajax({
  url: "http://someurl.com/api/random_post_action",
  type: "post",
  dataType: "json",
  data: post_json,
  success: function(data){
    console.log(data);
}});

给出random_post_action参数(ruby on rails):

{
  "stuff" => {
    "0" => {
        "1" => "foo"
    }
  },
  "controller" => "api",
  "action" => "random_post_action"
}

预期结果:

{
  "stuff" => [
    [0] {
          "1" => "foo"
        }
  ],
  "controller" => "api",
  "action" => "random_post_action"
}

我不确定发生了什么......

0 个答案:

没有答案