Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSON编码一个零值嵌入式JSON.MARSHALER PANICS,您会认为这是一个bug吗?_Json_Go_Interface_Marshalling - Fatal编程技术网

JSON编码一个零值嵌入式JSON.MARSHALER PANICS,您会认为这是一个bug吗?

JSON编码一个零值嵌入式JSON.MARSHALER PANICS,您会认为这是一个bug吗?,json,go,interface,marshalling,Json,Go,Interface,Marshalling,恐慌: json.NewEncoder(os.Stdout).Encode(struct { M json.Marshaler }{}) 我想为我的接口明确声明它应该自行封送: panic: interface conversion: interface is nil, not json.Marshaler 你认为这是错误吗?如果没有,为什么不呢?有趣的问题,我看到了争论双方的优点。有趣的问题,我看到了争论双方的优点。 type thing interface { jso

恐慌:

json.NewEncoder(os.Stdout).Encode(struct {
    M json.Marshaler
}{})

我想为我的接口明确声明它应该自行封送:

panic: interface conversion: interface is nil, not json.Marshaler 

你认为这是错误吗?如果没有,为什么不呢?

有趣的问题,我看到了争论双方的优点。有趣的问题,我看到了争论双方的优点。
type thing interface {
    json.Marshaler
    Type() string
    ....
}