如何解决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语言删除文件的方法

Go语言如何升级版本

Go语言导包时“.”和“_”的区别是什么?

Go语言有几种框架

Go语言程序如何编译

学习Go语言看什么书

Go语言 if 语句

Go语言字符串怎么求指定子串

Go语言转义字符有哪些

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




打赏

取消

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

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

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

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

评论

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