-1
私はC#で簡単なUnityゲームを開発しています。 Unityとデータベースの間でJSONデータを送り返したいと思います。 UnityのJsonUtility
を使用してデシリアライズしていますが、正しく処理することができません。C#Unity 5でオブジェクトにJSONを逆シリアル化する適切な方法は?
は、ここに私のJSONです:
{
"Table": {
"AttributeDefinitions":[
{
"AttributeName":"pleasework",
"AttributeType":"S"
}
],
"CreationDateTime":1.501013735355E9,
"ItemCount":0,
"KeySchema":[
{
"AttributeName":"pleasework",
"KeyType":"HASH"
}
],
"ProvisionedThroughput":{
"NumberOfDecreasesToday":0,
"ReadCapacityUnits":5,
"WriteCapacityUnits":5
},
"TableArn":"stringhere",
"TableId":"stringhere",
"TableName":"stringhere",
"TableSizeBytes":0,
"TableStatus":"ACTIVE"
}
}
はここでオブジェクトを作成するために私のコードです:ここで
RootObject res = RootObject.CreateFromJSON(www.text);
Debug.Log(res.Table.TableName);
は、クラスは次のとおりです。
[System.Serializable]
public class AttributeDefinition
{
public string AttributeName { get; set; }
public string AttributeType { get; set; }
}
[System.Serializable]
public class KeySchema
{
public string AttributeName { get; set; }
public string KeyType { get; set; }
}
[System.Serializable]
public class ProvisionedThroughput
{
public int NumberOfDecreasesToday { get; set; }
public int ReadCapacityUnits { get; set; }
public int WriteCapacityUnits { get; set; }
}
[System.Serializable]
public class Table
{
public List<AttributeDefinition> AttributeDefinitions { get; set; }
public double CreationDateTime { get; set; }
public int ItemCount { get; set; }
public List<KeySchema> KeySchema { get; set; }
public ProvisionedThroughput ProvisionedThroughput { get; set; }
public string TableArn { get; set; }
public string TableId { get; set; }
public string TableName { get; set; }
public int TableSizeBytes { get; set; }
public string TableStatus { get; set; }
}
[System.Serializable]
public class RootObject
{
public Table Table { get; set; }
public static RootObject CreateFromJSON(string json)
{
return JsonUtility.FromJson<RootObject>(json);
}
}
問題は私がDebug.Log(res.Table.TableName);
に電話すると、以下のエラーが出ます。
エラー:
NullReferenceException: Object reference not set to an instance of an object