duanji2772 2016-11-06 16:24
浏览 466

url.Values中的嵌套值

I'm working on an API client and I need to be able to send a nested JSON structure with a client.PostForm request. The issue I'm encountering is this:

reqBody := url.Values{
    "method": {"server-method"},
    "arguments": {
        "download-dir": {"/path/to/downloads/dir"},
        "filename":     {variableWithURL},
        "paused":       {"false"},
    },
}

When I try to go build this, I get the following errors:

./transmission.go:17: syntax error: unexpected :, expecting }
./transmission.go:24: non-declaration statement outside function body
./transmission.go:26: non-declaration statement outside function body
./transmission.go:27: non-declaration statement outside function body
./transmission.go:29: non-declaration statement outside function body
./transmission.go:38: non-declaration statement outside function body
./transmission.go:39: syntax error: unexpected }

I'm wondering what the correct way to created a nested set of values in this scenario. Thanks in advance!

  • 写回答

3条回答 默认 最新

  • dpt8910 2016-11-06 16:43
    关注

    You are not using properly the url.Values, according to the source code (url package, url.go):

    // Values maps a string key to a list of values.
    // It is typically used for query parameters and form values.
    // Unlike in the http.Header map, the keys in a Values map
    // are case-sensitive.
    type Values map[string][]string
    

    But arguments is not compliant with the definition because the object of arguments is not an array of strings.

    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。