Unity JSON必须表示对象类型

时间:2017-12-06 14:58:04

标签: c# json unity3d unity5

这是我的代码:

string jsonResult = System.Text.Encoding.UTF8.GetString(www.downloadHandler.data);          
Player player = JsonUtility.FromJson<Player>(jsonResult);
Debug.Log(player.testObj);

这是我的2级对象

[Serializable]
public class Player
{
public List<PlayerInfo> testObj;

}


[Serializable]
public class PlayerInfo
{
public string username;
public string password; 
public int age;
}

jsonResult包含一个json对象问题是什么时候使用JsonUtility.FromJson它告诉我:

  

ArgumentException:JSON必须表示对象类型。   UnityEngine.JsonUtility.FromJson [Player](System.String json)(在C:/buildslave/unity/build/artifacts/generated/common/modules/JSONSerialize/JsonUtilityBindings.gen.cs:25)   registerScript + c__Iterator2.MoveNext()(在Assets / registerScript.cs:78)   UnityEngine.SetupCoroutine.InvokeMoveNext(IEnumerator枚举器,IntPtr returnValueAddress)(在C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

这是我的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}]

0 个答案:

没有答案