You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"bytes"
"encoding/json"
"fmt"
)
func main() {
p := "404 not found"
var m interface{}
dec := json.NewDecoder(bytes.NewBuffer([]byte(p)))
dec.UseNumber()
err := dec.Decode(&m)
// the err is nil
if err != nil {
fmt.Println(err)
}
// 404
fmt.Println(m)
err = json.Unmarshal([]byte(p), &m)
// the err is not nil
if err != nil {
fmt.Println(err)
}
// 404
fmt.Println(m)
}
What did you expect to see?
both m is 404, but the first err is nil, and the second err is "invalid character 'n' after top-level value". Maybe both should reutrn error?
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?What did you do?
What did you expect to see?
both m is 404, but the first err is nil, and the second err is "invalid character 'n' after top-level value". Maybe both should reutrn error?
The text was updated successfully, but these errors were encountered: