using JetBrains.Annotations; using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using Unity.VisualScripting.Antlr3.Runtime; using UnityEngine; public class Test : MonoBehaviour { public string token; // 当接收到 token 时触发此方法,仅保存 token public void HandleTokenReceived(string receivedToken) { token = receivedToken; // 保存最新的 token // 首次调用加载初始数据 //LoadGameEscapeData(); // Debug.Log("接收到新的 token: " + token); } public UpdateUserInfo updateUserInfo; public int sec; // Start is called before the first frame update void Start() { // 注册监听事件,当收到 token 时,触发 HandleTokenReceived LoginAndGetToken.OnTokenReceived += HandleTokenReceived; updateUserInfo = new UpdateUserInfo(); } // Update is called once per frame void Update() { TestButton(); } public async void TestButton() { if(Input.GetKey(KeyCode.X)) { sjdlkjf(); //Debug.Log("nnnnnnnnnnnnnnnn"+sec); } } public async void sjdlkjf() { // 用来给请求头赋值 string Authorization = token; //Debug.Log("Loding(Authorization)请求头赋值" + Authorization); // 5.1查询最近一场大屠杀 Dictionary head51 = new Dictionary { { "Authorization", Authorization }, // 设置授权头 }; string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", head51); Debug.Log("5.1查询最近一场大屠杀(独立)" + response51); // 查询最近一场大逃亡游戏详情: // 解析JSON数据 string json = response51; Response response = JsonConvert.DeserializeObject(json); int gameEscapeId = response.data.gameEscapeModel.id; Debug.Log(gameEscapeId); //Debug.Log("解析成功,id为: " + gameEscapeId); int carrySeconds = response.data.carrySeconds; Debug.Log("====================================================================================="+carrySeconds); } } [Serializable] public class GameEscapeModel { public int id; // 解析游戏ID public string gameNo; // 包括游戏编号 } //[Serializable] //public class GameEscapeRoomResponseVo //{ // public int escapeId; // 逃脱游戏的ID // public int roomNo; // 房间号 //} [Serializable] public class Data { public int carrySeconds; // 持续秒数 public GameEscapeModel gameEscapeModel; // 嵌套的GameEscapeModel对象 //public List gameEscapeRoomResponseVoList; // 房间信息列表 public object gameEscapeUserModel; // 用户模型,可以保持为空或根据需要进行定义 } [Serializable] public class Response { public int code; // 状态码 public string message; // 返回信息 public Data data; // 数据对象 }