{"id":203292,"date":"2020-11-25T12:37:15","date_gmt":"2020-11-25T04:37:15","guid":{"rendered":"http:\/\/4563.org\/?p=203292"},"modified":"2020-11-25T12:37:15","modified_gmt":"2020-11-25T04:37:15","slug":"%e5%b5%8c%e5%a5%97%e8%87%aa%e8%ba%ab%e7%9a%84-struct-%e8%af%a5%e5%a6%82%e4%bd%95%e5%ae%9e%e4%be%8b%e5%8c%96%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=203292","title":{"rendered":"\u5d4c\u5957\u81ea\u8eab\u7684 Struct \u8be5\u5982\u4f55\u5b9e\u4f8b\u5316\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5d4c\u5957\u81ea\u8eab\u7684 Struct \u8be5\u5982\u4f55\u5b9e\u4f8b\u5316\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : miencun <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6709\u4e2a<\/p>\n<p>type A struct { B struct { Count int <code>json:\"count\"<\/code> Status int <code>json:\"status\"<\/code> } <code>json:\"b\"<\/code> }<\/p>\n<p>\u7528 A{B{Count: 112,Status: 112}}\u62a5\u6211\u6ca1\u6709\u5b9a\u4e49 B \u8bf7\u6559\u8bf7\u6559\uff0c\u67e5\u4e86\u4e00\u5929\u8d44\u6599\u8fd8\u6ca1\u641e\u5b9a\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4222694\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : miencun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5bf9\u4e86\uff0c\u6211\u4e0d\u60f3\u7528<br \/>var a A<br \/>a.B.Count = 1<br \/>a.B.Status = 2<br \/>\u8fd9\u79cd\u76f4\u63a5\u8d4b\u503c\u7684\u65b9\u6cd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4222695\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yrj <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u90a3\u5c31 type \u4e00\u4e2a b \u5457\u3002<br \/>type b struct\u2026\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4222696\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gy0624ww <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             type B struct {<br \/> Count int `json:&#8221;count&#8221;`<br \/> Status int `json:&#8221;status&#8221;`<br \/>}<br \/>type A struct {<br \/> B `json:&#8221;B&#8221;`<br \/>}<\/p>\n<p>func main() {<br \/> a := A{B{<br \/> Count: 11,<br \/> Status: 10,<br \/> }}<br \/> fmt.Println(a)<br \/>}                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4222697\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : miencun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e24\u4f4d\u8001\u54e5\u3002 @yrj @gy0624ww<\/p>\n<p>\u6211\u8981\u5d4c\u5957\u81ea\u8eab Struct\uff0c\u56e0\u4e3a\u9700\u8981\u8f93\u51fa\u7684 json \u5f88\u590d\u6742\uff0c\u5d4c\u5957\u81ea\u8eab\u8fd9\u6837\u770b\u8d77\u6765\u5f88\u723d                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4222698\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zealic <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;`go<br \/>type A struct {<br \/> B struct {<br \/> Count int `json:&#8221;count&#8221;`<br \/> Status int `json:&#8221;status&#8221;`<br \/> } `json:&#8221;b&#8221;`<br \/>}<\/p>\n<p>_ := A{<br \/> B: struct {<br \/> Count int `json:&#8221;count&#8221;`<br \/> Status int `json:&#8221;status&#8221;`<br \/> } {Count: 1, Status: 2},<br \/>}<br \/>&#8220;`<\/p>\n<p>\u8fd9\u4e2a\u73a9\u6cd5\u5e76\u4e0d\u597d\uff0c\u53cd\u800c\u66f4\u7e41\u7410\uff0c\u5982\u8981\u4fdd\u6301\u7c7b\u578b\u7684\u53cd\u5c04\u533f\u540d\u53ef\u4ee5\u7528 type def<\/p>\n<p>&#8220;`go<br \/>type X = struct {<br \/> Count int `json:&#8221;count&#8221;`<br \/> Status int `json:&#8221;status&#8221;`<br \/>} <br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4222699\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : keepeye <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ea\u80fd\u62c6\u51fa\u6765\u5b9a\u4e49                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4222700\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : airplayxcom <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u6740\u6211\u81ea\u5df1\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4222701\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : index90 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             A{B: struct {<br \/> Count int `json:&#8221;count&#8221;`<br \/> Status int `json:&#8221;status&#8221;`<br \/>}{Count: 1, Status: 2}}<\/p>\n<p>B \u4e0d\u662f\u7c7b\u578b\u540d\uff0c\u662f\u5b57\u6bb5\u540d<br \/>type A \u91cc\u9762\u7684 struct \u662f\u4e00\u4e2a\u533f\u540d\u7c7b\u578b<br \/>\u5b9e\u4f8b\u5316\u7684\u65f6\u5019\uff0c\u9700\u8981\u7b7e\u540d\u4e00\u81f4\uff0ctag \u90e8\u5206\u4e5f\u8981\u4e00\u6837                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4222702\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : miencun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @index90 \u8fd9\u5c31\u5f88\u7e41\u7410\u4e86\u554a\uff0c\u76f8\u5f53\u4e8e\u201c\u91cd\u65b0\u5b9a\u4e49\u201d\u4e00\u6b21\uff0c\u5982\u679c\u8fd9\u6837\u7684\u8bdd\uff0c\u6211\u76f4\u63a5\u7528\u8bbe\u7f6e B \u4e3a\u533f\u540d\u5c31\u884c\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5d4c\u5957\u81ea\u8eab\u7684 Struct \u8be5\u5982\u4f55\u5b9e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/203292"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203292"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/203292\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203292"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}