{"id":1152,"date":"2022-01-17T09:07:54","date_gmt":"2022-01-17T00:07:54","guid":{"rendered":"https:\/\/blog.wsd.sh\/?p=1152"},"modified":"2022-01-23T08:13:27","modified_gmt":"2022-01-22T23:13:27","slug":"golang-struct%e3%81%ae%e3%83%95%e3%82%a3%e3%83%bc%e3%83%ab%e3%83%89%e3%81%abomitempty%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%97%e3%81%9f%e6%99%82%e3%81%ae%e6%8c%af%e3%82%8b%e8%88%9e%e3%81%84","status":"publish","type":"post","link":"https:\/\/blog.wsd.sh\/?p=1152","title":{"rendered":"<small>Golang struct\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306bomitempty\u3092\u6307\u5b9a\u3057\u305f\u6642\u306e\u632f\u308b\u821e\u3044<\/small>"},"content":{"rendered":"<p>\uff11\uff0egolang struct\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306bomitempty\u3092\u6307\u5b9a\u3057\u305f\u6642\u306e\u632f\u308b\u821e\u3044<br \/>\n\u30fbnil\u3092\u5165\u308c\u305f\u6642\u306b\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u7701\u7565\u3055\u308c\u3066\u3044\u308b<br \/>\n\uff12\uff0ecode<\/p>\n<pre>\r\npackage main\r\n\r\nimport (\r\n    \"encoding\/json\"\r\n    \"fmt\"\r\n)\r\n\r\ntype Employee_s struct {\r\n    Num         *interface{} `json:\"num,omitempty\"`\r\n}\r\n\r\nfunc main() {\r\n\r\n   var NULL interface{};\r\n    employee := [7] Employee_s{}\r\n\r\n    var isNull_1,isNull_2,isNull_3,isNull_4,isNull_5  interface{};\r\n\r\n    isNull_1 = nil\r\n    isNull_2 = false\r\n    isNull_3 = true\r\n    isNull_4 = 0\r\n    isNull_5 = \"\"\r\n\r\n    employee[0].Num = &isNull_1;\r\n    employee[1].Num = &isNull_2;\r\n    employee[2].Num = &isNull_3;\r\n    employee[3].Num = &isNull_4;\r\n    employee[4].Num = &isNull_5;\r\n    employee[5].Num = nil\r\n    employee[6].Num = &NULL\r\n\r\n    json_string, _ := json.Marshal(employee)\r\n\r\n    fmt.Println(string(json_string))\r\n}\r\n<\/pre>\n<p>\uff13\uff0e\u7d50\u679c<\/p>\n<pre>\r\n[{\"num\":null},{\"num\":false},{\"num\":true},{\"num\":0},{\"num\":\"\"},{},{\"num\":null}]\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\uff11\uff0egolang struct\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306bomitempty\u3092\u6307\u5b9a\u3057\u305f\u6642\u306e\u632f\u308b\u821e\u3044 \u30fbnil\u3092\u5165\u308c\u305f\u6642\u306b\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u7701\u7565\u3055\u308c\u3066\u3044\u308b \uff12\uff0ecode package main import ( &#8220;encoding\/json&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/1152"}],"collection":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1152"}],"version-history":[{"count":5,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/1152\/revisions"}],"predecessor-version":[{"id":1154,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/1152\/revisions\/1154"}],"wp:attachment":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}