##概要
Unity(c#)でのサーバーから送られてきたデータをLitJsonを利用してオブジェクトにデシリアライズし、Text型オブジェクトに代入し表示するという実装を試みております。
取得したオブジェクトのキーとバリューをセットで取得し、利用したいのですがGET通信でのバリューの取得方法についてご教示願えますと幸いです。何卒よろしくお願いいたします。
##コード
クラス定義
[System.SerializableAttribute] public class Item { public string name; public string grade; public int birthday; public string instrument; }
通信部分
private IEnumerator Get(){ Dictionary<string, string> header = new Dictionary<string, string>(); header.Add("Accepted-Language", "ja"); WWW www = new WWW(url); yield return www; //JSONを外部のJSONファイルで定義したクラスオブジェクトに変換し、オブジェクトのクラスを定義 string txt = www.text; Debug.Log("www.text: " + www.text); Item item = JsonMapper.ToObject<Item>(txt); Debug.Log("name: " + item.name); Debug.Log("birthday: " + item.birthday); Debug.Log("grade: " + item.grade); Debug.Log("instrument: " + item.instrument); Name.text = item.name; Grade.text = item.grade; Birthday.text = item.birthday.ToString(); Instrument.text = item.instrument;
##エラー内容
NullReferenceException: Object reference not set to an instance of an object
##出力結果
GETしたリクエスト
www.text: {"user":{"id":61,"created_at":"2017-09-05T01:39:45.000Z","updated_at":"2017-09-05T06:18:39.000Z","access_token":"61:YB6jPzRUa54qLs6k-f9F","grade":"1www","birthday":1234,"name":"panther","instrument":"2eee"}}
name: UnityEngine.Debug:Log(Object)
birthday: 0 UnityEngine.Debug:Log(Object)
grade: UnityEngine.Debug:Log(Object)
instrument: UnityEngine.Debug:Log(Object)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/06 03:26