I have a problem with json decoder in Go. I have client (dotnet core) and server (go) which are communicate via sockets. Encoding is setted to utf-8. After decoding on server side is not one of string in correct format.
Go decoding code:
buf := make([]byte, bufferSize)
_, err := conn.Read(buf)
if err != nil {
fmt.Println("Error reading:", err.Error())
}
s := string(buf[:])
r := strings.NewReader(s)
d := json.NewDecoder(r)
request := Request{}
d.Decode(&request)
Variable s contains correct string before decoding: https://i.stack.imgur.com/EUYF3.png and args contains correct word "zářit".
After decoding is string broken and contains this: https://i.stack.imgur.com/Zqan8.png
I don't understand representation ...+2 more from second image and I don't know how to decode this string correct way.
EDIT:
The core of the problem can be reproduced by this code:
package main
import (
"fmt"
"encoding/json"
"strings"
)
type Request struct {
Arg string
}
func main() {
s := "{\"Arg\": \"zářit\"}"
r := strings.NewReader(s)
d := json.NewDecoder(r)
request := Request{}
d.Decode(&request)
for i := 0; i < len(request.Arg); i++ {
char := request.Arg[i]
fmt.Print(string(char))
}
fmt.Println()
fmt.Println(request.Arg)
}
Why output is not the same? How I should get the same result?