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.

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

报告相同问题?