This question already has an answer here:
I'm trying to unmarshal a json object to struct in Go. I tried to stick to this example but I can't get it to work. The result stays empty.
Code:
package main
import (
"encoding/json"
"fmt"
)
type MyObject struct {
id string
pubKey string
}
func main() {
x := `{"id":"abc","pubKey":"QIDAQAB"}`
fmt.Println("Input: ", x)
var myObject MyObject
json.Unmarshal([]byte(x), &myObject)
fmt.Println("Output: ", myObject)
}
Output:
Input: {"id":"abc","pubKey":"QIDAQAB"}
Output: { }
I found a lot of similar questions but I can't even see a difference between the working example and my non-working code. What am I missing?
</div>