如何解决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语言通过命令方式生成可执行文件

windows下怎么搭建Go语言开发环境

Go语言函数

Go语言范围(range)

Go语言最适合做什么

Go语言类型转换

Go语言运算符

Go语言 for 循环

Go语言适合用在哪方面

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




打赏

取消

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

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

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

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

评论

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