{"id":3858,"date":"2023-07-14T18:21:47","date_gmt":"2023-07-14T09:21:47","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=3858"},"modified":"2023-07-14T18:37:10","modified_gmt":"2023-07-14T09:37:10","slug":"%e3%80%90go%e3%80%91json%e8%aa%ad%e3%81%bf%e8%be%bc%e3%81%bf-%e6%83%b3%e5%ae%9a%e5%a4%96%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bf","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=3858","title":{"rendered":"\u3010Go\u3011Json\u8aad\u307f\u8fbc\u307f \u60f3\u5b9a\u5916\u30d1\u30e9\u30e1\u30fc\u30bf"},"content":{"rendered":"\n<p>json\u30a2\u30f3\u30de\u30fc\u30b7\u30e3\u30eb\u3067\u60f3\u5b9a\u5916\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3093\u3060\u5834\u5408\u306e\u6319\u52d5\u306b\u3064\u3044\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h1 class=\"wp-block-heading\">\u30a2\u30f3\u30de\u30fc\u30b7\u30e3\u30eb\u30a8\u30e9\u30fc(\u30d1\u30fc\u30b9\u30a8\u30e9\u30fc)<\/h1>\n\n\n\n<p>\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">json\u30d5\u30a1\u30a4\u30eb<\/h2>\n\n\n\n<p>&#8220;name&#8221; \u30ad\u30fc\u306e\u5024 &#8220;sampleName&#8221; \u306e\u5f8c\u306b\u30ab\u30f3\u30de(,)\u304c\u5b58\u5728\u3059\u308b\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-json\" data-lang=\"JSON\"><code>{\n    &quot;name&quot;: &quot;sample_name&quot;,\n    &quot;events&quot;: [\n        {\n            &quot;age&quot;: 10,\n            &quot;name&quot;: &quot;sampleName&quot;,\n        }\n    ]\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;encoding\/json&quot;\n\t&quot;fmt&quot;\n\t&quot;os&quot;\n)\n\n\/\/ Json\u306e\u5185\u5bb9\u3092\u683c\u7d0d\u3059\u308b\u69cb\u9020\u4f53\ntype history struct {\n\tName   string  `json:&quot;name&quot; example:&quot;sampleName&quot;`\n\tEvents []event `json:&quot;events&quot;`\n}\n\ntype event struct {\n\tAge  int    `json:&quot;age&quot; example:&quot;10&quot;`\n\tName string `json:&quot;name&quot; example:&quot;eventName&quot;`\n}\n\nfunc main() {\n\n\th := history{}\n\n\t\/\/ \u30d5\u30a1\u30a4\u30eb\u8aad\u307f\u8fbc\u307f\n\tf, err := os.Open(&quot;sample.json&quot;)\n\tif err != nil {\n\t\treturn\n\t}\n\n\t\/\/ \u30c7\u30b3\u30fc\u30c9\n\te := json.NewDecoder(f).Decode(&h)\n\tif e != nil {\n\t\tfmt.Println(e) \/\/ invalid character &#39;}&#39; looking for beginning of object key string\n\t}\n}<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u30d1\u30e9\u30e1\u30fc\u30bf\u578b\u9055\u3044<\/h1>\n\n\n\n<p>\u60f3\u5b9a\u3057\u306a\u3044\u578b\u3092\u8aad\u307f\u8fbc\u3093\u3060\u5834\u5408\u3001\u60f3\u5b9a\u3057\u3066\u3044\u308b\u578b\u306e\u30bc\u30ed\u5024\u304c\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">json\u30d5\u30a1\u30a4\u30eb<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-json\" data-lang=\"JSON\"><code>{\n    &quot;name&quot;: &quot;sample_name&quot;,\n    &quot;events&quot;: [\n        {\n            &quot;age&quot;: &quot;\u5341\u4e00&quot;,\n            &quot;name&quot;: 0\n        }\n    ]\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>package main\n\nimport (\n\t&quot;encoding\/json&quot;\n\t&quot;fmt&quot;\n\t&quot;os&quot;\n)\n\n\/\/ Json\u306e\u5185\u5bb9\u3092\u683c\u7d0d\u3059\u308b\u69cb\u9020\u4f53\ntype history struct {\n\tName   string  `json:&quot;name&quot; example:&quot;sampleName&quot;`\n\tEvents []event `json:&quot;events&quot;`\n}\n\ntype event struct {\n\tAge  int    `json:&quot;age&quot; example:&quot;10&quot;`\n\tName string `json:&quot;name&quot; example:&quot;eventName&quot;`\n}\n\nfunc main() {\n\n\th := history{}\n\n\t\/\/ \u30d5\u30a1\u30a4\u30eb\u8aad\u307f\u8fbc\u307f\n\tf, err := os.Open(&quot;sample.json&quot;)\n\tif err != nil {\n\t\treturn\n\t}\n\n\t\/\/ \u30c7\u30b3\u30fc\u30c9\n\tjson.NewDecoder(f).Decode(&h)\n\n\tfor _, v := range h.Events {\n\n\t\t\/\/ int\n\t\tfmt.Println(v.Age) \/\/ 0 \u304c\u8868\u793a\u3055\u308c\u308b\n\n\t\t\/\/ string\n\t\tif v.Name == &quot;&quot; {\n\t\t\tfmt.Println(&quot;\u30d6\u30e9\u30f3\u30af\u3067\u3059\u3002&quot;) \/\/ &quot;\u30d6\u30e9\u30f3\u30af\u3067\u3059\u3002&quot; \u304c\u8868\u793a\u3055\u308c\u308b\n\t\t}\n\t}\n}<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u30d1\u30e9\u30e1\u30fc\u30bf\u304cNULL<\/h1>\n\n\n\n<p>NULL\u3092\u8aad\u307f\u8fbc\u3093\u3060\u5834\u5408\u3001\u60f3\u5b9a\u3057\u3066\u3044\u308b\u578b\u306e\u30bc\u30ed\u5024\u304c\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">json\u30d5\u30a1\u30a4\u30eb<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>{\n    &quot;name&quot;: &quot;sample_name&quot;,\n    &quot;events&quot;: [\n        {\n            &quot;age&quot;: null,\n            &quot;name&quot;: null\n        }\n    ]\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0<\/h2>\n\n\n\n<p>\u540c\u3058\u306a\u306e\u3067\u5272\u611b\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>json\u30a2\u30f3\u30de\u30fc\u30b7\u30e3\u30eb\u3067\u60f3\u5b9a\u5916\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3093\u3060\u5834\u5408\u306e\u6319\u52d5\u306b\u3064\u3044\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":968,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-3858","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go"],"_links":{"self":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3858"}],"version-history":[{"count":4,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3858\/revisions"}],"predecessor-version":[{"id":3862,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3858\/revisions\/3862"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/968"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}