Golang 将 JSON 对象传递给函数

Golang pass JSON object to a function

这个算是Selenium Web driver不过我觉得不是很重要。

我可以设置浏览器名称

caps := selenium.Capabilities{"browserName": "firefox"}
wd, _ := selenium.NewRemote(caps, "")

但对于 "proxy" 即:

caps := selenium.Capabilities{"proxy": "http://1.2.3.4:999"}
wd, _ := selenium.NewRemote(caps, "")

我必须传递一个 JSON Proxy Object,我完全不知道如何创建...我到处搜索,但仍然无法理解...它是一种结构吗?或地图..或什么... :-(

正如我在评论中所说,您可以使用表格

selenium.Capabilities{
    "proxy": map[string]interface{}{
        "httpProxy": "http://1.2.3.4:999",
        // etc.
    }
}

非结构化 JSON 通常(未)通过 map[string]interface{} 编组,类型 selenium.Capabilities 实际上只是 map[string]interface{}.

另请参阅:JSON and Go