Unityでのjsonを取得し使用する方法がわからないので教えてください
miniJsonというライブラリ?を用いて開発をしました。
内容は表示しているText(郵便番号)を取得し郵便番号から住所を取得し表示するものです。
どうやら GetAddress メソッドにすら到達していないそうです。
以下がC#のコードです。
C#
1using HoloToolkit.Unity.InputModule; 2using System; 3using UnityEngine; 4using MiniJSON; 5using System.Collections; 6 7public class PostNumberSearch : MonoBehaviour, IInputClickHandler 8{ 9 public GameObject postCode; 10 public GameObject address; 11 private String text = "",number; 12 // Use this for initialization 13 void Start () { 14 } 15 16 // Update is called once per frame 17 void Update () { 18 19 } 20 public void OnInputClicked(InputClickedEventData eventData) 21 { 22 String number=postCode.GetComponent<TextMesh>().text; 23 Debug.Log(number); 24 StartCoroutine("GetAddress"); 25 //GetAddress(number); 26 address.GetComponent<TextMesh>().text = text; 27 } 28 IEnumerable GetAddress() 29 { 30 Debug.Log(number); 31 WWW www = new WWW("http://zipcloud.ibsnet.co.jp/api/search?zipcode="+number); 32 yield return www; 33 if (www.error != null) 34 { 35 Debug.Log("Error"); 36 } 37 else 38 { 39 Debug.Log("Success"); 40 string json = www.text; 41 IList spheres = (IList)Json.Deserialize(json); 42 foreach (IDictionary sphere in spheres) 43 { 44 IList address = (IList)sphere["results"]; 45 for (int i = 0; i < address.Count; i++) 46 { 47 Debug.Log((String)address[i]); 48 text = text + (String)address[i]; 49 } 50 } 51 } 52 } 53} 54
回答1件
あなたの回答
tips
プレビュー