我使用下面的代码生成字符串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.
我该如何解决?
字节[239 191 189]是Unicode替换字符的UTF-8编码.
XML封送程序将字节0x1替换为Unicode替换字符,因为字节0x01不是XML中的合法字符.
无法阻止XML封送程序使用替换.
| 归档时间: |
|
| 查看次数: |
133 次 |
| 最近记录: |