如何解决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语言导包时“.”和“_”的区别是什么?

Go语言适合做什么?

Go语言开发工具有哪些

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




打赏

取消

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

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

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

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

评论

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