dongzouhe9734 2017-10-25 02:57
浏览 17
已采纳

在Go中解码URL

I am calling an API that is returning a URL in a UTF-8 encoded XML document. The parsing is returning something like http://www.test.com and I want to convert it to http://www.test.com.

I'm struggling to find the right way to do this. Any help would be appreciated!

Edit: this code does what I need, but would have thought there would have been a pre-built function that does something similar to this website: https://www.url-encode-decode.com/

    for _, user := range x.Users {
        a := strings.Replace(user.Username, ":", ":", -1)
        b := strings.Replace(a, "/", "/", -1)
        fmt.Println(b)
    }
  • 写回答

1条回答 默认 最新

  • dqef7931 2017-10-25 05:18
    关注

    Just call html.UnescapeString("http://www.test.com") which results in http://www.test.com.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 易语言编写cs.16 绘制 矩阵出现了点问题 不知道这个矩阵可不可以使用
    • ¥15 k210显示failed init to model
    • ¥15 Evil-droid生成的APK手机已经下载但无法建立任务
    • ¥25 c语言韩信点兵的变式
    • ¥15 怎么根据书上的例子完成这个问题呢?
    • ¥15 ECharts 增加Zoom,整行包括右边的Text一起滑动
    • ¥15 关于网上一个easyx制作的见缝插针小游戏(c++)
    • ¥15 开地址法双散列函数处理碰撞
    • ¥15 想问一下这个是什么情况 虚拟机Linux打不开了
    • ¥15 联通光猫掉注册了怎么重新注册上去