Encoding 使用对_查询的活动支持对参数进行编码不会为数组生成正确的字符串
我正在尝试将散列编码为HTTP参数。为此,我使用activesupport的方法Encoding 使用对_查询的活动支持对参数进行编码不会为数组生成正确的字符串,encoding,url-parameters,activesupport,Encoding,Url Parameters,Activesupport,我正在尝试将散列编码为HTTP参数。为此,我使用activesupport的方法 options = {:mail=>"dabrother+jido@gmail.com", :firstName=>"Henrieeto", :lastName=>"brother", :sendCredentials=>"true", :lang=>"fr", :groups
options = {:mail=>"dabrother+jido@gmail.com",
:firstName=>"Henrieeto",
:lastName=>"brother",
:sendCredentials=>"true",
:lang=>"fr",
:groups=>["60ac8ef4cf911758a54a1307"]}
options.to_query
生成
"firstName=Henrieeto&groups%5B%5D=60ac8ef4cf911758a54a1307&lang=fr&lastName=brother&mail=dabrother%2Bjido%40gmail.com&sendCredentials=true"
然后,如果我URI.decode(options.to\u query)
,我得到
"firstName=Henrieeto&groups[]=60ac8ef4cf911758a54a1307&lang=fr&lastName=brother&mail=dabrother+jido@gmail.com&sendCredentials=true"
这不是我所期望的,因为groups[]=60ac8ef4cf911758a54a1307
不是预期的输出,它应该是groups[0]=60ac8ef4cf911758a54a1307
我在这里做错了什么?如何在选项哈希中正确编码数组