{"id":93130,"date":"2020-03-28T22:48:17","date_gmt":"2020-03-28T14:48:17","guid":{"rendered":"http:\/\/4563.org\/?p=93130"},"modified":"2020-03-28T22:48:17","modified_gmt":"2020-03-28T14:48:17","slug":"%e8%af%b7%e6%95%99%e4%b8%80%e4%b8%aa-go-%e8%af%ad%e8%a8%80%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=93130","title":{"rendered":"\u8bf7\u6559\u4e00\u4e2a go \u8bed\u8a00\u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u6559\u4e00\u4e2a go \u8bed\u8a00\u7684\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rimutuyuan <\/span>  <span><i><\/i> 20<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>type Person struct {     Name string `json:\"name\"` }  var p *Person  s := `{\"name\": \"123\"}` fmt.Println(json.Unmarshal([]byte(s), p))  \/\/ \u62a5\u9519 fmt.Println(json.Unmarshal([]byte(s), &amp;p)) \/\/ \u6210\u529f <\/code><\/pre>\n<p>var \u58f0\u660e\u53d8\u91cf\uff0cp \u5e94\u8be5\u662f nil\uff0c\u4e3a\u4ec0\u4e48\u53d6\u5730\u5740 json \u53cd\u5e8f\u5217\u5316\u53cd\u800c\u6210\u529f\u4e86\uff0c\u4e0d\u662f\u5f88\u7406\u89e3\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1005024\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : reus <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             p \u662f nil\uff0c\u6240\u4ee5\u62a5\u9519<br \/>&amp;p \u4e0d\u662f nil\uff0c\u6240\u4ee5\u6210\u529f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1005025\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kidlj <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Unmarshal \u7b2c\u4e8c\u4e2a\u53c2\u6570\u5fc5\u987b\u662f\u4e2a\u6307\u9488\uff0c\u800c\u4e14\u4e0d\u80fd\u4e3a nil\uff0c\u4f46\u662f p == nil\uff0c\u6240\u4ee5\u7b2c\u4e00\u4e2a\u62a5\u9519\u3002<\/p>\n<p>&#8220;`<br \/>func (d *decodeState) unmarshal(v interface{}) error {<br \/> rv := reflect.ValueOf(v)<br \/> if rv.Kind() != reflect.Ptr || rv.IsNil() {<br \/> return &amp;InvalidUnmarshalError{reflect.TypeOf(v)}<br \/> }<br \/>&#8230;<\/p>\n<p>}<br \/>&#8220;`<\/p>\n<p>\u81f3\u4e8e\u7b2c\u4e8c\u4e2a\uff0c&amp;p \u662f\u6307\u5411 p \u53d8\u91cf\uff08\u672c\u8eab\u662f\u4e2a\u6307\u9488\uff09\u7684\u6307\u9488\uff0c&amp;p \u65e2\u662f\u6307\u9488\uff0c\u53c8\u4e0d\u662f nil\uff0c\u6240\u4ee5\u4e0d\u62a5\u9519\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1005026\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : janxin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u62a5\u9519\u4fe1\u606f\u6709\u7684\u554a\uff0c\u56e0\u4e3a\u662f nil&#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1005027\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brzhang <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u95ee\u4e00\u4e2a\u95ee\u9898\uff0c\u7a7a\u503c\u4e00\u5b9a\u662f nil \u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u6559\u4e00\u4e2a go \u8bed\u8a00\u7684\u95ee\u9898 \u8cc7\u6df1\u5927&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\/93130"}],"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=93130"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/93130\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=93130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=93130"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=93130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}