I have a web service that returns an empty list (just []
).
JsonUtility.FromJson
is giving me an
ArgumentException: JSON must represent an object type.
I have isolated this down to a bit of code as simple as:
string empty = "[]";
FriendManager.FriendList test = JsonUtility.FromJson<FriendManager.FriendList>(empty);
Assert.IsNotNull(test);
FriendList
is just a wrapper for Friend[]
. I also tried List<Friend>
:
string empty = "[]";
FriendManager.FriendList test = JsonUtility.FromJson<List<Friend>>(empty);
Assert.IsNotNull(test);
Am I missing something obvious?
I have control over the server data (Spring Boot JSON web service) and the client (Unity3D).
From this thread
so your second attempt will not work. And you also cannot directly asign it to
FriendManager.FriendList
if it s of typeList<Friend>
as you said.You rather need a wrapper class for it like e.g.
make
FriendManaget.FriendList
of typeFriendList
And than either the server or you have to append the field name to that array namely the name of the variable:
Friends
e.g. likeor the server has to send