具有主动支持 to_query 的编码参数不会为数组生成正确的字符串

问题描述

我正在尝试将哈希编码为 HTTP 参数。为此,我使用了 activesupport 的 to_query 方法

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_query),我得到

"firstName=Henrieeto&groups[]=60ac8ef4cf911758a54a1307&lang=fr&lastName=brother&mail=dabrother+jido@gmail.com&sendCredentials=true"

这不是我所期望的,因为 groups[]=60ac8ef4cf911758a54a1307 不是预期的输出,它应该是 groups[0]=60ac8ef4cf911758a54a1307

在这里做错了什么,如何正确编码选项哈希中的数组?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)