{"id":2523,"date":"2017-07-27T16:40:35","date_gmt":"2017-07-27T07:40:35","guid":{"rendered":"http:\/\/nantoka.filmm.info\/blog\/?p=2523"},"modified":"2017-07-27T16:40:35","modified_gmt":"2017-07-27T07:40:35","slug":"unity%e3%81%abjson%e3%81%a7%e8%a4%87%e9%9b%91%e3%81%aa%e6%83%85%e5%a0%b1%e3%82%92%e3%81%97%e3%81%be%e3%81%a3%e3%81%a1%e3%82%83%e3%81%86","status":"publish","type":"post","link":"https:\/\/nantoka.filmm.info\/blog\/?p=2523","title":{"rendered":"Unity\u306bJSON\u3067\u8907\u96d1\u306a\u60c5\u5831\u3092\u3057\u307e\u3063\u3061\u3083\u3046"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>\u72ec\u81ea\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059<\/p>\n<pre class=\"lang:default decode:true \" title=\"myData.cs\">[System.Serializable]\r\npublic class myData {\r\n\tpublic int id;\r\n\tpublic string name;\r\n\tpublic int time;\r\n\tpublic float posx;\r\n\tpublic float posy;\r\n\tpublic float posz;\r\n\r\n}\r\n<\/pre>\n<p>1\u884c\u76ee\u304c\u5358\u306bSerializable\u3068\u306a\u3063\u3066\u3044\u308b\u3082\u306e\u304c\u3042\u308b\u304c\uff0cSystem\u3092\u3064\u3051\u308b\u3068\u52d5\u304f<\/p>\n<p>&nbsp;<\/p>\n<p>\u6b21\u306b\u3053\u308c\u3092Dictionary\u306b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\uff08\u5de6=key\uff09\uff0cJSON\u6587\u5b57\u5217\uff08\u53f3\uff1dvalue\uff09\u306e\u30bb\u30c3\u30c8\u3067\u4fdd\u5b58\u3057\u307e\u3059<\/p>\n<p>\u3053\u306e\u5834\u5408\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u306f\u304a\u305d\u3089\u304f\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u3055\u305b\u3066\u9806\u5e8f\u3088\u304f\u518d\u751f\u3055\u305b\u305f\u65b9\u304c\u7121\u96e3<\/p>\n<p>&nbsp;<\/p>\n<p>\u767b\u9332\uff06\u547c\u3073\u51fa\u3057\u306f\u3053\u3061\u3089\uff0e\u4eca\u56de\u306f\u30c6\u30b9\u30c8\u306a\u306e\u3067\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u304c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u756a\u53f7\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\uff0c\u3053\u308c\u3067\u306f\u76ee\u6a19\u306e\u3053\u3068\u304c\u3067\u304d\u306a\u3044<\/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\r\n\tpublic GameObject ballPre;\r\n\tpublic InputField numInput;\r\n\r\n\tDictionary&lt;int, string&gt; timeList2;\r\n\r\n\tvoid Start () {\r\n\r\n\t\ttimeList2  = new Dictionary&lt;int, string&gt; ();\r\n\r\n\r\n\t\t\/\/json test\r\n\t\tmyData jdata = new myData();\r\n\r\n\t\t\/\/\u30ad\u30e3\u30e9\uff4e\u4f53\u4f5c\u6210\r\n\t\tfor (int i = 0; i &lt; 10; i++) {\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\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);\r\n\r\n\t\t\ttimeList2.Add (i, json);\r\n\t\t}\r\n\t}\r\n\t\r\n\r\n\t\/\/\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3067JSON\u3092\u547c\u3073\u51fa\u3059\r\n\tpublic void numDel(){\r\n\t\tint objNum = int.Parse (numInput.text);\/\/\u5165\u529b\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u6587\u5b57\u3092int\u306b\u5909\u63db\r\n\t\tvar myObject = JsonUtility.FromJson&lt;myData&gt;(timeList2 [objNum]);\/\/\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3067\u547c\u3073\u51fa\u3057\u305fValue\u3092JSON\u6587\u5b57\u5217\u304b\u3089\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5909\u63db\r\n\t\tDebug.Log (\"X=\" + myObject.posx);\/\/\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5185\u306eposx\u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u4ee5\u4e0b\u540c\u3058\u30d1\u30bf\u30f3\r\n\t\tDebug.Log (\"Y=\" + myObject.posy);\r\n\t\tDebug.Log (\"name=\" + myObject.name);\r\n\t\tDebug.Log (\"time=\" + myObject.time);\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>key\u3092\u30b7\u30fc\u30f3\u756a\u53f7\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u3069\u3046\u3059\u308c\u3070\uff0c\uff0c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u72ec\u81ea\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059 [System.Serializable] public class myData { public int id; public string name; public int t &hellip; <a href=\"https:\/\/nantoka.filmm.info\/blog\/?p=2523\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Unity\u306bJSON\u3067\u8907\u96d1\u306a\u60c5\u5831\u3092\u3057\u307e\u3063\u3061\u3083\u3046<\/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-2523","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\/2523","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=2523"}],"version-history":[{"count":1,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2523\/revisions"}],"predecessor-version":[{"id":2524,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2523\/revisions\/2524"}],"wp:attachment":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}