小编kat*_*ley的帖子

使用HTTParty发送数组变量

我正在使用HTTParty发送POST请求.所需的变量之一是数组.这是我用来发送的代码:

response = HTTParty.post url, :body => 
    {"key"=>'XYZ123',
    "content"=>
        [{"placename"=>"placeholder",
        "placecontent"=>"sample content"}],
    etc. }
Run Code Online (Sandbox Code Playgroud)

API需要看到:

"content": [
    {
        "placename": "placeholder",
        "placecontent": "sample content"
    }
],
Run Code Online (Sandbox Code Playgroud)

但是,当我检查API上的请求收到日志时,我看到我的代码正在生成:

"content": [
    {
        "placename": "placeholder"
    },
    {
        "placecontent": "sample content"
    }
],
Run Code Online (Sandbox Code Playgroud)

如何阻止数组记录分成两部分?

谢谢.

编辑:所需的代码输出相当于:

...&content[0][placename]=placeholder&content[0][placecontent]=sample%20content...
Run Code Online (Sandbox Code Playgroud)

ruby arrays post httparty

2
推荐指数
1
解决办法
2868
查看次数

标签 统计

arrays ×1

httparty ×1

post ×1

ruby ×1