如何解决go语言乱码问题


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

package main

// gopm get -g -v golang.org/x/text

import (

"net/http"

"fmt"

"io/ioutil"

"golang.org/x/text/encoding/simplifiedchinese"

// "golang.org/x/text/encoding/simplifiedchinese"

"golang.org/x/text/transform"

)

func main()  {

fmt.Println("hello world")

resp, err := http.Get("http://city.zhenai.com/xian")

if err != nil {

panic(err)

}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {

fmt.Println("Error: status code", resp.StatusCode)

return

}

utf8Reader := transform.NewReader(resp.Body,

simplifiedchinese.GBK.NewDecoder())

all, err := ioutil.ReadAll(utf8Reader)

if err != nil {

panic(err)

}

fmt.Printf("%s\n", all)

}

更多相关技术文章,请访问golang教程栏目!

以上就是如何解决go语言乱码问题的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Go语言适合做什么?

Go语言相对于c/c++有什么优势

Go语言实现之基于websocket浏览器通知功能

Go语言使用正则表达式提取网页文本

Go语言的多行注释是什么

Go语言中函数与方法有什么区别

Go语言用什么ide

Go语言多维数组

Go语言有什么特点?

Go语言有框架吗

更多相关阅读请进入《Go语言》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...