{"id":13085,"date":"2021-02-06T09:40:31","date_gmt":"2021-02-06T00:40:31","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=13085"},"modified":"2023-05-27T22:31:47","modified_gmt":"2023-05-27T13:31:47","slug":"%e3%80%90ruby%e3%80%91json%e3%82%92%e5%87%a6%e7%90%86%e3%81%99%e3%82%8b%e3%81%ab%e3%81%af%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=13085","title":{"rendered":"\u3010Ruby\u3011JSON\u3092\u51e6\u7406\u3059\u308b\u3001\u30d5\u30a1\u30a4\u30eb\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6271\u3046\u30af\u30e9\u30b9"},"content":{"rendered":"<h2>JSON(String)\u3092\u30cf\u30c3\u30b7\u30e5\u306b\u5909\u63db\u3059\u308b\u3002<\/h2>\n<h3>\u69cb\u6587<\/h3>\n<p>Ruby\u306eJSON\u6587\u5b57\u5217(String)\u3092\u30cf\u30c3\u30b7\u30e5\u5f62\u5f0f\u306b\u5909\u63db\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">JSON.parse(JSON\u6587\u5b57\u5217, \u30aa\u30d7\u30b7\u30e7\u30f3)<\/pre>\n<h4>JSON\u6587\u5b57\u5217<\/h4>\n<p>Ruby\u3067\u306fString\u578b\u306b\u306a\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h4>\u30aa\u30d7\u30b7\u30e7\u30f3<\/h4>\n<table>\n<tbody>\n<tr>\n<th>\u30aa\u30d7\u30b7\u30e7\u30f3\u540d<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>max_nesting<\/td>\n<td>JSON\u6587\u5b57\u5217\u306e\u30cd\u30b9\u30c8\u306e\u6df1\u3055\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306f19<\/td>\n<\/tr>\n<tr>\n<td>symbolize_names<\/td>\n<td>\u5909\u63db\u3057\u305f\u30cf\u30c3\u30b7\u30e5\u306e\u30ad\u30fc\u3092\u30b7\u30f3\u30dc\u30eb\u306b\u3057\u307e\u3059\u3002(true\/false)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u30cf\u30c3\u30b7\u30e5\u3092JSON(String)\u306b\u5909\u63db\u3059\u308b\u3002<\/h2>\n<p>\u9006\u306b\u30cf\u30c3\u30b7\u30e5\u3092JSON\u306b\u3057\u305f\u3044\u5834\u5408\u306f\u7c21\u5358\u3067\u3059\u3002\u30cf\u30c3\u30b7\u30e5\u30af\u30e9\u30b9\u306e<span style=\"color: #ff0000;\"><strong>to_json\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u3092\u4f7f\u3046\u3060\u3051\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">\u30cf\u30c3\u30b7\u30e5.to_json<\/pre>\n<h2>\u30d5\u30a1\u30a4\u30eb\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u64cd\u4f5c<\/h2>\n<h3>File\u30af\u30e9\u30b9<\/h3>\n<p>\u7d44\u307f\u8fbc\u307f\u30e9\u30a4\u30d6\u30e9\u30ea\u3067require\u306a\u3057\u3067\u52d5\u304f<\/p>\n<h4>\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210<\/h4>\n<pre class=\"lang:default decode:true\">File.new(\"test.txt\",\"w\")\r\nfile.puts('1\u884c\u76ee')\r\nfile.puts('2\u884c\u76ee')\r\nfile.close\u304b<\/pre>\n<h5>\u66f8\u304d\u8fbc\u307f\u30e2\u30fc\u30c9<\/h5>\n<table>\n<tbody>\n<tr>\n<td>\u30aa\u30d7\u30b7\u30e7\u30f3<\/td>\n<td>\u8aac\u660e<\/td>\n<\/tr>\n<tr>\n<td>w<\/td>\n<td>\u65e2\u5b58\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u5834\u5408\u306f\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u3092\u7a7a\u306b\u3059\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td>w+<\/td>\n<td>\u65e2\u5b58\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u306f\u7a7a\u306b\u3059\u308b\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Dir\u30af\u30e9\u30b9<\/h3>\n<p>\u7d44\u307f\u8fbc\u307f\u30e9\u30a4\u30d6\u30e9\u30ea\u3067require\u306a\u3057\u3067\u52d5\u304f<\/p>\n<h3>FileUtils\u30e2\u30b8\u30e5\u30fc\u30eb<\/h3>\n<p>\u57fa\u672c\u7684\u306a\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u3092\u96c6\u3081\u305f\u30e2\u30b8\u30e5\u30fc\u30eb(Unix\u3001Linux\u30b3\u30de\u30f3\u30c9\u3092Ruby\u304b\u3089\u547c\u3073\u51fa\u305b\u308b\u3088\u3046\u306b\u3059\u308b\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u3059\u3002\uff09<\/p>\n<pre class=\"lang:default decode:true \">require 'Fileutils'\r\nFileUtils.touch(\"test\")<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308btouch\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u5834\u5408\u306f\u4e0a\u8a18\u306e\u3088\u3046\u306a\u8a18\u8ff0\u65b9\u6cd5\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>Pathname\u30af\u30e9\u30b9<\/h3>\n<p>\u30d1\u30b9\u540d\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u3089\u3057\u304f\u6271\u3046\u30af\u30e9\u30b9<\/p>\n<h2>\u30d5\u30a1\u30a4\u30eb\u5165\u51fa\u529b<\/h2>\n<p>\u4e0a\u8a18\u3067\u7d39\u4ecb\u3057\u305fJSON\u30af\u30e9\u30b9\u4ee5\u5916\u306b\u3082CSV\u3001YAML\u306a\u3069\u306e\u30af\u30e9\u30b9\u3082\u5b58\u5728\u3057\u307e\u3059\u3002<\/p>\n<h3>CSV<\/h3>\n<p>CSV\u3084TSV\uff08\u30bf\u30d6\u533a\u5207\u308a\uff09\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u3080\u3053\u3080\u5834\u5408\u306b\u4f7f\u3048\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">require 'csv'\r\n\r\nCSV.foreach('csv\u306e\u30d1\u30b9\u540d') do |aaa|\r\n  # aaa\u306fArray\u30af\u30e9\u30b9\r\n  puts \"[#{aaa[0]}] #{aaa[1]}\"\r\nend<\/pre>\n<p>\u4e0a\u8a18\u306f\u3001\u65e2\u5b58\u306eCSV\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u53d6\u3063\u3066\u5024\u3092\u53d6\u308a\u51fa\u3057\u3066\u51fa\u529b\u3055\u305b\u308b\u30b5\u30f3\u30d7\u30eb\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">require 'csv'\r\n\r\nCSV.parse('aaa,bbb,ccc') do |gyo|\r\n  puts gyo[0] # =&gt; 'aaa'\r\n  puts gyo[1] # =&gt; 'bbb'\r\n  puts gyo[2] # =&gt; 'ccc'\r\nend<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3058\u3083\u306a\u304f\u3066\u3082csv\u306bparse\u3059\u308c\u3070\u53d6\u308a\u51fa\u3059\u3053\u3068\u306f\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h3>YAML<\/h3>\n<p>YAML\u5f62\u5f0f\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u5834\u5408\u306b\u4f7f\u3048\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"JSON(String)\u3092\u30cf\u30c3\u30b7\u30e5\u306b\u5909\u63db\u3059\u308b\u3002 \u69cb\u6587 Ruby\u306eJSON\u6587\u5b57\u5217(String)\u3092\u30cf\u30c3\u30b7\u30e5\u5f62\u5f0f\u306b\u5909\u63db\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002 JSON.parse(JSON\u6587\u5b57\u5217, \u30aa\u30d7\u30b7\u30e7\u30f3) JSON\u6587\u5b57\u5217 Ruby\u3067\u306fSt [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[48],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13085"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13085"}],"version-history":[{"count":7,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13085\/revisions"}],"predecessor-version":[{"id":20469,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13085\/revisions\/20469"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13085"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}