{"id":352404,"date":"2021-02-15T06:45:31","date_gmt":"2021-02-14T22:45:31","guid":{"rendered":"http:\/\/4563.org\/?p=352404"},"modified":"2021-02-15T06:45:31","modified_gmt":"2021-02-14T22:45:31","slug":"go-json-%e7%9b%ae%e5%89%8d%e6%8e%a8%e8%8d%90%e7%94%a8%e5%93%aa%e4%b8%aa%e5%ba%93","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=352404","title":{"rendered":"Go json \u76ee\u524d\u63a8\u8350\u7528\u54ea\u4e2a\u5e93"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Go json \u76ee\u524d\u63a8\u8350\u7528\u54ea\u4e2a\u5e93               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : garyox64 <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>Go \u65b0\u624b \u6c42\u95ee\u73b0\u5728 \u4e3b\u6d41 json \u7528\u54ea\u4e2a \u5e93 \u770b\u4e86\u4e00\u4e9b\u8bc4\u6d4b\u597d\u50cf \u5c0f json \u7528 jsonparser [ https:\/\/github.com\/buger\/jsonparser ] \u5927\u7684\u7528 jsoniter [ https:\/\/github.com\/json-iterator\/go ] \uff1f<\/p>\n<p>\u7136\u540e\u6211\u73b0\u5728\u5728\u7528 jsoniter\uff0c\u6ca1\u6587\u6863\u592a\u75db\u82e6\u4e86 \u5efa struct \u6765\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316 \u592a\u9ebb\u70e6\u4e86\uff0c\u56e0\u4e3a\u6211\u662f\u590d\u6742 json\uff0c\u60f3\u8ffd\u6c42 py \u7684 json \u4f7f\u7528\u4f53\u9a8c\uff0c \u76ee\u524d\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u53d6\u503c \u53ef\u4ee5\u7528 Get + \u8def\u5f84\u53d6\u503c\uff0c\u4f46\u662f\u4e5f\u53ea\u662f\u53d6\u503c\u800c\u5df2\uff0c\u540e\u9762\u8fd8\u8981\u6539\u503c\uff0c\u518d\u63a8\u9001\u597d\u50cf\u5c31\u6ca1\u6cd5\u5b50\u53ea\u80fd\u5efa struct \uff1f \u770b\u4e86\u90e8\u5206\u6587\u7ae0\uff0cjsoniter \u5e94\u8be5\u662f\u53ef\u4ee5 \u505a\u5230\u7c7b\u4f3c py \u7684\u4f53\u9a8c\u7684\uff1f\uff1f\u4f46\u662f\u5b9e\u5728\u6ca1\u627e\u5230\u8be6\u7ec6\u7684\u6587\u6863<\/p>\n<p>\u6c42\u52a9\u5927\u4f6c\u6307\u8def\u6216\u8005 \u7ed9\u4e2a\u6837\u4f8b\uff0c\u9700\u6c42\uff1ajson \u76f4\u63a5\u8f6c struct \u4e4b\u7c7b\u7684\uff0c\u50cf py \u4e00\u6837\u7684\u4f53\u9a8c<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>5<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5328806\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : shoaly <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u8fc7 php \u6216\u8005 python \u7684 json \u90fd\u975e\u5e38\u5f00\u5fc3<\/p>\n<p>\u5230 go \u8fd9\u8fb9 \u771f\u7684\u5934\u75db&#8230; \u7b80\u5355\u7684 json \u7ed3\u6784\u8fd8\u597d, \u5c31\u6015\u78b0\u5230\u90a3\u79cd\u5c42\u7ea7\u7279\u522b\u590d\u6742\u7684 json, \u5404\u79cd\u6570\u7ec4\u5d4c\u5957, \u6570\u7ec4\u5957\u6570\u7ec4\u7684\u65f6\u5019 , \u7b80\u76f4\u60f3\u54ed&#8230; \u6628\u5929\u5c31\u78b0\u5230\u4e00\u4e2a json \u4f8b\u5b50 \u6597\u4e86\u534a\u5929\u624d\u641e\u51fa\u6765, \u613f\u610f\u7ec3\u624b\u7684\u670b\u53cb \u53ef\u4ee5\u8bd5\u8bd5\u600e\u4e48\u5728 go \u91cc\u9762 \u5b9e\u4f8b\u5316\u4e00\u4e2a struct \u5bf9\u5e94\u5230\u4e0b\u9762\u8fd9\u4e2a json, \u70e6\u70b9\u5c31\u5728 \u90a3\u4e2a inline_keyboard \u91cc\u9762\u7684\u6570\u636e\u7ed3\u6784<br \/>{&#8220;chat_id&#8221;:&#8221;123&#8243;,&#8221;reply_markup&#8221;:{&#8220;inline_keyboard&#8221;:[[{&#8220;text&#8221;:&#8221;text&#8221;,&#8221;callback_data&#8221;:&#8221;callback:success&#8221;},{&#8220;text&#8221;:&#8221;text&#8221;,&#8221;callback_data&#8221;:&#8221;callback:fail&#8221;}]]},&#8221;reply_to_message_id&#8221;:&#8221;112&#8243;,&#8221;text&#8221;:&#8221;hello&#8221;}                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5328807\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : heiheidewo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/github.com\/bitly\/go-simplejson                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5328808\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ladit <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u516c\u53f8\u7528\u7684\u662f jsoniter\uff0c\u4e0d\u8fc7\u6ca1\u6709\u7279\u522b\u590d\u6742\u7684\u64cd\u4f5c\u3002<\/p>\n<p>@shoaly #1 \u5982\u679c\u7ed3\u6784\u662f\u9884\u5148\u77e5\u9053\u7684\uff0c\u8fd9\u4e2a\u5de5\u5177\u633a\u597d\u7528\u7684\uff1a https:\/\/mholt.github.io\/json-to-go\/ \uff0c\u5982\u679c\u662f\u52a8\u6001\u7684\uff0c\u786e\u5b9e\u6bd4\u8f83\u56f0\u6270\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5328809\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : shoaly <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ladit \u8001\u54e5 \u4f60\u771f\u662f\u53ef\u7231\u7684\u4eba&#8230;.. \u8fd9\u4e2a\u5730\u5740\u6211\u4e4b\u524d\u8981\u77e5\u9053 \u5c31\u4e0d\u7528\u82b1\u534a\u4e2a\u5c0f\u65f6\u53bb\u51d1 struct \u4e86..                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5328810\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LIncoln666 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @heiheidewo \u725b\u76ae\uff0c\u6536\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Go json \u76ee\u524d\u63a8\u8350\u7528\u54ea\u4e2a\u5e93 &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\/352404"}],"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=352404"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/352404\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352404"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}