在JSON中识别void and intscepified字段,在JSON中,JSON中的JSON
[ {“ name”:“ a”,“ description”:“ monotremata”}, {“ name”:“ b”}, {“名称”:“ C”,“描述”:“”} ] 如果我们定义了这样的GO结构:
and unmarshal the JSON into a slice of Category instances, we get the following output:[{Name:A Description:Monotremata} {Name:B Description:} {Name:C Description:}]Notice that the Description field of B is an empty string, while the Description field of C is completely omitted from the JSON.在这两种情况下,描述字段都设置为GO表示中的一个空字符串。[ {"Name": "A", "Description": "Monotremata"}, {"Name": "B"}, {"Name": "C", "Description": ""} ]很大,一种方法是一种方法,一种方法是将指针用于可选字段。通过将描述类型更改为指针,我们可以区分空字符串值和零值(指示未指定的字段):
类型类别struct { 名称字符串 描述 *字符串 } [&& && && && && && &&华描述C的字段是指向空字符串的指针(由十六进制内存地址指示)。这使我们能够识别未指定的字段并在我们的程序中相应处理。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3