请问 go 获取 post 请求返回体的 字符类型为[]uint8, 但是是 xml 的格式,怎么转换成 json

2022-11-10 14:46:08 +08:00
 lewis0xx001
919 次点击
所在节点    Go 编程语言
7 条回复
lewis0xx001
2022-11-10 14:47:07 +08:00
body, err := ioutil.ReadAll(res.Body)
fmt.Println("post send success")
fmt.Printf("type is %T\n", body)
结果:
post send success
type is []uint8
<?xml version="1.0" encoding="utf-8" ?><returnsms>
<errorstatus>
<error>2</error>
<remark>sign 参数错误</remark>
</errorstatus>
</returnsms>
lewis0xx001
2022-11-10 14:49:33 +08:00
@lewis0xx001
<?xml version="1.0" encoding="utf-8" ?><returnsms>
<errorstatus>
<error>2</error>
<remark>sign 参数错误</remark>
</errorstatus>
</returnsms>
是 string() 后的打印结果
lewis0xx001
2022-11-10 14:50:55 +08:00
直接打印 body 是
body is []byte{0x3c, 0x3f, 0x78, 0x6d, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x22, 0x31, 0x2e, 0x30, 0x22, 0x20, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3d, 0x22, 0x75, 0x74, 0x66, 0x2d, 0x38, 0x22, 0x20, 0x3f, 0x
3e, 0x3c, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x6d, 0x73, 0x3e, 0xa, 0x20, 0x3c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3e, 0xa, 0x20, 0x3c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x3e, 0x32, 0x3c, 0x2f, 0x65, 0x72, 0x7
2, 0x6f, 0x72, 0x3e, 0xa, 0x20, 0x3c, 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x3e, 0x73, 0x69, 0x67, 0x6e, 0xe5, 0x8f, 0x82, 0xe6, 0x95, 0xb0, 0xe9, 0x94, 0x99, 0xe8, 0xaf, 0xaf, 0x3c, 0x2f, 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x3e, 0xa, 0x20, 0x3c
, 0x2f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3e, 0xa, 0x20, 0x3c, 0x2f, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x6d, 0x73, 0x3e, 0xa, 0x20}
lewis0xx001
2022-11-10 15:11:31 +08:00
有没有大佬给个思路呀
haohu108123
2022-11-10 15:19:02 +08:00
这个其实网上一搜 一大堆。
herold519
2022-11-10 17:01:40 +08:00
鸟哥那图谁来贴一下?
yaott2020
2022-11-10 17:27:21 +08:00
自己搜:golang xml 解析,网上一抓一大把

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/894145

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX