Skip to content

Instantly share code, notes, and snippets.

@mozhata
Created March 14, 2016 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mozhata/61d11bbcdbf80e984c83 to your computer and use it in GitHub Desktop.
Save mozhata/61d11bbcdbf80e984c83 to your computer and use it in GitHub Desktop.
golang怎样通过http获取json数据?
我发现http包似乎不能接受结构比较复杂的json
比如有一json数据大概是这个样子:
```
{
"links": [
{
"text": {
"zh-cn": "百度",
"en-us": "baidu"
},
"link": "www.baidu.com"
},
{
"text": {
"zh-cn": "百度2",
"en-us": "baidu"
},
"link": "www.baidu.com"
}
]
}
我通过post方法发送到go服务器, 在服务器端打印了一下request请求, 部分数据如下:
"Body": {},
"ContentLength": 109,
"TransferEncoding": null,
"Close": false,
"Host": "goserver:8855",
"Form": {
"links": [
"text",
"link",
"text",
"link",
"text",
"link",
"text",
"link",
"text",
"link"
]
},
"PostForm": {
"links": [
"text",
"link",
"text",
"link",
"text",
"link",
"text",
"link",
"text",
"link"
]
}
查了一下http包的Request, 发现Form, PostForm都是url.Values 就是map[string][]string, 这样的话更复杂一点的结构,
比如我上面贴的那种, 用golang应该怎么处理呢?
@mozhata
Copy link
Author

mozhata commented Apr 19, 2016

body

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment