Hello,
Im trying to retrieve the data from Title Data and store it into an Object.
As key i have Enemies and the Values are:
{ "enemies": [ { "id": 1, "name": "Pete", "hp": 50, "dmg": 5 }, { "id": 2, "name": "Jamie", "hp": 75, "dmg": 7 }, { "id": 3, "name": "Paul", "hp": 100, "dmg": 10 } ] }
Now im trying to create Objects from my Class Enemy
[Serializable] public class Enemy { public string name; public int id; public int hp; public int dmg; }
And here is my code:
//Get Enemies Stats public void get_enemystats() { var request = new GetTitleDataRequest(); PlayFabClientAPI.GetTitleData(request, onEnemyResult, onEnemyError); } private void onEnemyError(PlayFabError obj) { Debug.Log("Failed to get Enemy stats"); } public void onEnemyResult(GetTitleDataResult obj) { Debug.Log("Getting enemies Stats"); Debug.Log(obj.Data.Values.ToString()); Enemy enemynow = JsonUtility.FromJson<Enemy>(obj.Data.Values.ToString()); Debug.Log(enemynow.name); //Debug.Log(enemynow.dmg); }
Do i have to define, which key i want to retrieve? For now i have only this one.
I keep getting errors on the Json parsing line, can someone please help me, what is wrong?
Maybe its the obj.Data.Values is a Dictionary?