{"id":3736,"date":"2022-12-30T14:02:12","date_gmt":"2022-12-30T06:02:12","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3736"},"modified":"2022-12-30T14:02:12","modified_gmt":"2022-12-30T06:02:12","slug":"%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84json%e8%ae%80%e5%af%ab","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/go\/%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84json%e8%ae%80%e5%af%ab\/","title":{"rendered":"\u5b78\u7fd2Go\u8a9e\u8a00\u4e2d\u7684JSON\u8b80\u5beb"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Go, JSON, \u8b80\u5beb\"><\/p>\n<h1>\u4f7f\u7528 Go \u8a9e\u8a00\u8b80\u5beb JSON<\/h1>\n<p>Go \u8a9e\u8a00\u662f\u4e00\u7a2e\u975e\u5e38\u6d41\u884c\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u958b\u767c\u5404\u7a2e\u61c9\u7528\u7a0b\u5f0f\uff0c\u5176\u4e2d\u5305\u62ec\u8b80\u5beb JSON \u683c\u5f0f\u7684\u8cc7\u6599\u3002JSON \u683c\u5f0f\u7684\u8cc7\u6599\u662f\u4e00\u7a2e\u6a19\u6e96\u7684\u8cc7\u6599\u683c\u5f0f\uff0c\u53ef\u4ee5\u7528\u4f86\u5b58\u5132\u548c\u50b3\u8f38\u8cc7\u6599\uff0cGo \u8a9e\u8a00\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u51fd\u5f0f\u5eab\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u7684\u8b80\u5beb JSON \u683c\u5f0f\u7684\u8cc7\u6599\u3002<\/p>\n<h2>Go \u8a9e\u8a00\u8b80\u53d6 JSON \u683c\u5f0f\u7684\u8cc7\u6599<\/h2>\n<p>Go \u8a9e\u8a00\u63d0\u4f9b\u4e86\u4e00\u500b\u5167\u5efa\u7684\u51fd\u5f0f\u5eab\u53ef\u4ee5\u8b80\u53d6 JSON \u683c\u5f0f\u7684\u8cc7\u6599\uff0c\u8a72\u51fd\u5f0f\u5eab\u53ef\u4ee5\u8b80\u53d6 JSON \u683c\u5f0f\u7684\u5b57\u4e32\u6216\u662f\u6a94\u6848\uff0c\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\uff0c\u53ef\u4ee5\u8b80\u53d6\u4e00\u500b JSON \u683c\u5f0f\u7684\u5b57\u4e32\uff1a<\/p>\n<pre class=\"brush: go\">\npackage main\n\nimport (\n    \"encoding\/json\"\n    \"fmt\"\n)\n\nfunc main() {\n    jsonData := `{\"name\": \"John\", \"age\": 30}`\n    var data map[string]interface{}\n    json.Unmarshal([]byte(jsonData), &data)\n    fmt.Println(data[\"name\"], data[\"age\"])\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u8f38\u51fa\uff1a<\/p>\n<pre>\nJohn 30\n<\/pre>\n<p><!--more--><\/p>\n<h2>Go \u8a9e\u8a00\u5beb\u5165 JSON \u683c\u5f0f\u7684\u8cc7\u6599<\/h2>\n<p>Go \u8a9e\u8a00\u4e5f\u63d0\u4f9b\u4e86\u4e00\u500b\u5167\u5efa\u7684\u51fd\u5f0f\u5eab\u53ef\u4ee5\u5c07\u8cc7\u6599\u5beb\u5165 JSON \u683c\u5f0f\uff0c\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\uff0c\u53ef\u4ee5\u5c07\u4e00\u500b\u8cc7\u6599\u7d50\u69cb\u5beb\u5165 JSON \u683c\u5f0f\u7684\u5b57\u4e32\uff1a<\/p>\n<pre class=\"brush: go\">\npackage main\n\nimport (\n    \"encoding\/json\"\n    \"fmt\"\n)\n\ntype Person struct {\n    Name string\n    Age  int\n}\n\nfunc main() {\n    person := Person{Name: \"John\", Age: 30}\n    jsonData, _ := json.Marshal(person)\n    fmt.Println(string(jsonData))\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u8f38\u51fa\uff1a<\/p>\n<pre>\n{\"Name\":\"John\",\"Age\":30}\n<\/pre>\n<h2>\u7e3d\u7d50<\/h2>\n<p>Go \u8a9e\u8a00\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u51fd\u5f0f\u5eab\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u7684\u8b80\u5beb JSON \u683c\u5f0f\u7684\u8cc7\u6599\uff0c\u9019\u4e9b\u51fd\u5f0f\u5eab\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u7684\u958b\u767c\u51fa\u53ef\u4ee5\u8b80\u5beb JSON \u683c\u5f0f\u7684\u61c9\u7528\u7a0b\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u4ecb\u7d39Go\u8a9e\u8a00\u4e2d\u7684JSON\u8b80\u5beb\uff0c\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Go\u8a9e\u8a00\u5c0dJSON\u683c\u5f0f\u7684\u8cc7\u6599\u9032\u884c\u8b80\u53d6\u3001\u5beb\u5165\u3001\u89e3\u6790\u7b49\u64cd\u4f5c\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u64cd\u4f5cJSON\u683c\u5f0f\u7684\u8cc7\u6599\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[171,172],"tags":[169,170],"class_list":["post-3736","post","type-post","status-publish","format-standard","hentry","category-go","category-golang","tag-go","tag-golang"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-Yg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=3736"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3736\/revisions"}],"predecessor-version":[{"id":3737,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3736\/revisions\/3737"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}