外部程序包的自定义JSON封送处理 [英] Custom JSON marshaling for external packages
本文介绍了外部程序包的自定义JSON封送处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从外部包向结构添加自定义JSON封送处理?我无法将MarshalJSON
和UnmarshalYAML
添加到这些结构中.
How can I add custom JSON marshaling to structs from external packages? I am unable to add the MarshalJSON
and UnmarshalYAML
to these structs.
推荐答案
您可以将该结构添加到您定义的结构中.然后将功能MarshalJSON
和UnmarshalYAML
添加到您的结构中:
You could add that struct to one defined by you. Then add the functions MarshalJSON
and UnmarshalYAML
to your struct:
type YourStruct struct {
ImportedStruct
}
func (s *YourStruct) MarshalJSON() ([]byte, error) {
...
}
这篇关于外部程序包的自定义JSON封送处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文