【发布时间】:2020-06-24 18:04:36
【问题描述】:
我正在尝试构建多人游戏,其中 Java 是我的服务器,Unity 是我的 Clinet。 我能够将数据发送到服务器并在服务器(Java 服务器)中以 Json 格式读取数据但是当我尝试读取响应时,我遇到了问题。我无法正确地将 Json 响应映射到在 Unity 中创建的类。
请在下面找到。
public class Player
{
public string playerID;
public string name;
public string playerPosX;
public string playerPosY;
public string playerPosZ;
}
public class Lobby
{
public string lobbyID;
public ArrayList player;
}
lobby = JsonUtility.FromJson<Lobby>(response);
Debug.Log(lobby.lobbyID);
Debug.Log(lobby.player.Count);
我将 json 数据作为
{"player":[{"playerID":"P1","name":"","playerPosX":"","playerPosY":"","playerPosZ":"","myne":false}],
"lobbyID":"L1"
}
我收到以下错误。 在第二个日志 对象引用未设置为对象的实例
【问题讨论】: