作者热门文章
- xml - XML 和 XSD 有什么区别?
- xml - XSD - 如何允许元素以任意顺序任意次数出现?
- xml - XML 区分大小写吗?
- sql-server - 从 SQL Server 2008 中的 XML 字段中选择值
如 encoding/json
包文档中所述,
Marshal traverses the value v recursively. If an encountered value implements the Marshaler interface and is not a nil pointer, Marshal calls its MarshalJSON method to produce JSON.
到底在哪里in the code执行此测试吗?
换句话说,encoding/json
如何检查 t
类型的值 v
是否实现了 Marshaller
界面?
最佳答案
这里:
Golang encoding/json Marshaler
if t.Implements(marshalerType) {
return marshalerEncoder
}
编辑:上面的链接已更新为指向特定版本的 Go,正如@dave-c 在下面的评论中指出的那样。
关于Golang 编码/json 编码(marshal)拆收器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31074404/
我是一名优秀的程序员,十分优秀!