我有一个条件,我需要将参数作为哈希数组传递,如下所示:
以下是 API 调用的 Rack::Test post 方法。
post "#{url}.json",
:api_key => application.key,
:data => [{"Company"=>"Apple,Inc","Website"=>"Apple.com"},{"Company"=>"Google","Website"=>"google.com"}],
:run => { :title => "The First Run" }
这是 rails 应用程序的日志。
Parameters: {"api_key"=>"6a9acb84d0ea625be75e70a1e04d26360606ca5b", "data"=>[{"Company"=>"Apple,Inc", "Website"=>"Apple.com"}, {"Company"=>"Google", "Website"=>"google.com"}], "run"=>{"title"=>"The First Run"}, "line_id"=>"4e018e2c55112729bd00000a"}
现在,这是我用来调用 API 的 RestClient post 方法。
RestClient.post("/lines/#{@line.id}/runs.json", {:run => {:title => @title}, @param_for_input => @param_data})
这是 rails 应用程序的日志。
Parameters: {"run"=>{"title"=>"run name"}, "data"=>{"Company"=>"Google", "Website"=>"google.com"}, "api_key"=>"f488a62d0307e79ec4f1e6131fa220be47e83d44", "line_id"=>"4e018a505511271f82000144"}
区别在于data
参数。
使用 Rack::Test 方法发送时,数据作为"data"=>[{"Company"=>"Apple,Inc", "Website"=>"Apple.com"}, {"Company"=>"Google", "Website"=>"google.com"}]
但通过 RestClient 方式,参数数据数组被剥离,只有最后一个哈希作为"data"=>{"Company"=>"Google", "Website"=>"google.com"}
为什么 RestClient 将散列数组剥离为数组的最后一个散列?