{"id":2525,"date":"2017-07-27T17:29:54","date_gmt":"2017-07-27T08:29:54","guid":{"rendered":"http:\/\/nantoka.filmm.info\/blog\/?p=2525"},"modified":"2017-07-27T17:31:35","modified_gmt":"2017-07-27T08:31:35","slug":"unity%e3%81%abjson%e3%81%a7%e8%a4%87%e9%9b%91%e3%81%aa%e6%83%85%e5%a0%b1%e8%a8%98%e9%8c%b2%ef%bc%92","status":"publish","type":"post","link":"https:\/\/nantoka.filmm.info\/blog\/?p=2525","title":{"rendered":"Unity\u306bJSON\u3067\u8907\u96d1\u306a\u60c5\u5831\u8a18\u9332\uff12"},"content":{"rendered":"<p>Dictionary\u306e\u4e2d\u306bList\u3092\u5165\u308c\u308b\u3053\u3068\u3067\u89e3\u6c7a\u3092\u306f\u304b\u3063\u3066\u307f\u308b\u5b9f\u9a13<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">using System.Collections;\r\nusing System.Collections.Generic;\r\nusing UnityEngine;\r\nusing UnityEngine.UI;\r\n\r\nusing System.Collections.Generic;\/\/\u5fc5\u305a\u5fc5\u8981\r\n\r\npublic class dicPractice : MonoBehaviour {\r\n\r\n\tpublic GameObject ballPre;\/\/\u30dc\u30fc\u30eb\u30d7\u30ec\u30d5\u30a1\u30d6\u7528\r\n\tpublic InputField numInput;\/\/\u30a4\u30f3\u30d7\u30c3\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u7528\r\n\r\n\tDictionary&lt;int, List&lt;string&gt;&gt; timeList1;\/\/\u591a\u91cd\u5316\r\n\tList&lt;string&gt; tempList ;\/\/\u30c6\u30f3\u30dd\u30e9\u30ea\u7528\u306eList\r\n\r\n\tvoid Start () {\r\n\t\t\/\/Dictionary,List\u306e\u8ffd\u52a0\r\n\t\ttimeList1 = new Dictionary&lt;int, List&lt;string&gt;&gt; ();\r\n\t\ttempList = new List&lt;string&gt;();\r\n\r\n\t\t\/\/json\u7528\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\r\n\t\tmyData jdata = new myData();\r\n\r\n\t\t\/\/\u30ad\u30e3\u30e910\u4f53\u4f5c\u6210\r\n\t\tfor (int i = 0; i &lt; 10; i++) {\r\n\t\t\t\r\n\t\t\tGameObject go = Instantiate (ballPre, new Vector3 (i * 2.0f, 0, 0), Quaternion.identity) as GameObject;\r\n\t\t\tstring myAIname =  \"AI\" + i.ToString ();\r\n\t\t\tgo.name = myAIname;\r\n\r\n\t\t\t\/\/json\u5316\u6e96\u5099\r\n\t\t\tjdata.id = i;\r\n\t\t\tjdata.name = myAIname;\r\n\t\t\tjdata.posx = go.transform.position.x;\r\n\t\t\tjdata.posy = go.transform.position.y;\r\n\t\t\tjdata.posz = go.transform.position.z;\r\n\t\t\tjdata.time = i * 10;\/\/dummy data\r\n\t\t\t\t\r\n\t\t\tstring json = JsonUtility.ToJson (jdata);\/\/\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092JSON\u6587\u5b57\u5217\u306b\u5909\u66f4\r\n\r\n\t\t\ttempList.Add (json);\/\/LIST\u306bJSON\u3092\u8ffd\u52a0\r\n\r\n\t\t}\r\n\r\n\t\ttimeList1.Add (0, tempList);\/\/\u3053\u306e\u30bc\u30ed\u306f\u30b7\u30fc\u30f3\u756a\u53f7\u3092\u60f3\u5b9a\u4e2d\u3044\u305a\u308c\uff0c\u5909\u6570\u3067\u5897\u3084\u3059\r\n\r\n\t}\r\n\t\t\r\n\r\n\t\/\/\u756a\u53f7\u3067\u8868\u793a\r\n\tpublic void numDel(){\r\n\t\tint objNum = int.Parse (numInput.text);\/\/\u30a4\u30f3\u30d7\u30c3\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u3067\u53d7\u3051\u53d6\u3063\u305f\u756a\u53f7\u3092int\u306b\u5909\u63db\r\n\t\tList&lt;string&gt; temp2List = new List&lt;string&gt; ();\/\/\u4e00\u6642\u7684\u306aList\u4f5c\u6210\r\n\t\ttemp2List = timeList1 [0];\/\/\u30b7\u30fc\u30f3\u756a\u53f70\u306eJSON\u3092LIST\u306b\u8aad\u307f\u8fbc\u3080\r\n\t\tvar myObject = JsonUtility.FromJson&lt;myData&gt;(temp2List [objNum]);\/\/\u30b7\u30fc\u30f3\u30bc\u30ed\u306eobjNum\u756a\u306eJSON\u306e\u307f\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5909\u63db\r\n\t\tDebug.Log (\"X=\" + myObject.posx);\/\/\u30c7\u30d0\u30c3\u30b0\u7528\r\n\t\tDebug.Log (\"Z=\" + myObject.posz);\r\n\t\tDebug.Log (\"name=\" + myObject.name);\r\n\t\tDebug.Log (\"time=\" + myObject.time);\r\n\r\n\t}\r\n\r\n\r\n\r\n}\r\n<\/pre>\n<p>\u30b7\u30fc\u30f3\u756a\u53f7\u3092\u5909\u6570\u5316\u3057\uff0ccount\u3067\u9577\u3055\u51fa\u3057\u3066\u5168\u90e8\u547c\u3073\u51fa\u3057\u3066\u518d\u914d\u7f6e\u3059\u308b\u306e\u3068\uff0c\u8a18\u9332\u3059\u308b\u306e\u3092\u4f5c\u308b<\/p>\n<p>\u3042\u308c\uff0c\uff0c\u8a18\u9332\u3059\u308b\u305f\u3081\u306b\uff0c\u3082\u4e00\u500bDictionary\u304c\u5fc5\u8981\u304b\u306a\uff1f\u8a18\u9332\u3059\u308b\u5bfe\u8c61\u3092\u6307\u5b9a\u3059\u308b\u306e\u306b\u4f7f\u3046\u305f\u3081\u306b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dictionary\u306e\u4e2d\u306bList\u3092\u5165\u308c\u308b\u3053\u3068\u3067\u89e3\u6c7a\u3092\u306f\u304b\u3063\u3066\u307f\u308b\u5b9f\u9a13 &nbsp; using System.Collections; using System.Collections.Generic; using U &hellip; <a href=\"https:\/\/nantoka.filmm.info\/blog\/?p=2525\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Unity\u306bJSON\u3067\u8907\u96d1\u306a\u60c5\u5831\u8a18\u9332\uff12<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,2,48],"tags":[],"class_list":["post-2525","post","type-post","status-publish","format-standard","hentry","category-c","category-unity","category-48"],"_links":{"self":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2525"}],"version-history":[{"count":2,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2525\/revisions"}],"predecessor-version":[{"id":2527,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2525\/revisions\/2527"}],"wp:attachment":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}