小编liu*_*ing的帖子

Go xml.Marshal返回无效字符

我使用下面的代码生成字符串str的XML编码:

str := string([]byte{0x01})
marshalBytes, _ := xml.Marshal(str)
fmt.Println(string(marshalBytes)) // output: <string>?</string>; ? is [239 191 189] in bytes.
Run Code Online (Sandbox Code Playgroud)

显然, 不等于0x01.

我该如何解决?

xml encoding go

1
推荐指数
1
解决办法
133
查看次数

标签 统计

encoding ×1

go ×1

xml ×1