Created
March 14, 2016 14:19
-
-
Save mozhata/61d11bbcdbf80e984c83 to your computer and use it in GitHub Desktop.
golang怎样通过http获取json数据?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
我发现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应该怎么处理呢? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
body