V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
lewis0xx001
V2EX  ›  Go 编程语言

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

  •  1
     
  •   lewis0xx001 · 2022-11-10 14:46:08 +08:00 · 1110 次点击
    这是一个创建于 745 天前的主题,其中的信息可能已经有所发展或是发生改变。
    lewis0xx001
        1
    lewis0xx001  
    OP
       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
        2
    lewis0xx001  
    OP
       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
        3
    lewis0xx001  
    OP
       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
        4
    lewis0xx001  
    OP
       2022-11-10 15:11:31 +08:00
    有没有大佬给个思路呀
    haohu108123
        5
    haohu108123  
       2022-11-10 15:19:02 +08:00
    这个其实网上一搜 一大堆。
    herold519
        6
    herold519  
       2022-11-10 17:01:40 +08:00
    鸟哥那图谁来贴一下?
    yaott2020
        7
    yaott2020  
       2022-11-10 17:27:21 +08:00 via Android
    自己搜:golang xml 解析,网上一抓一大把
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1117 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:33 · PVG 07:33 · LAX 15:33 · JFK 18:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.