This is my code:
string jsonResult = System.Text.Encoding.UTF8.GetString(www.downloadHandler.data);
Player player = JsonUtility.FromJson<Player>(jsonResult);
Debug.Log(player.testObj);
this is my 2 class objects
[Serializable]
public class Player
{
public List<PlayerInfo> testObj;
}
[Serializable]
public class PlayerInfo
{
public string username;
public string password;
public int age;
}
jsonResult contains a json object the problem is when is use JsonUtility.FromJson it tells me :
ArgumentException: JSON must represent an object type. UnityEngine.JsonUtility.FromJson[Player] (System.String json) (at C:/buildslave/unity/build/artifacts/generated/common/modules/JSONSerialize/JsonUtilityBindings.gen.cs:25) registerScript+c__Iterator2.MoveNext () (at Assets/registerScript.cs:78) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
this is my json:
[{"id":2,"username":"hamza","password":"22","age":123456,"created_at":"2017-12-06 09:36:23","updated_at":"2017-12-06 09:36:23"},{"id":3,"username":"Hamdi","password":"1234556","age":55,"created_at":null,"updated_at":null},{"id":4,"username":"Sonia","password":"5646546556","age":25,"created_at":null,"updated_at":null}]