using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Threading.Tasks; using Newtonsoft.Json; using System; //查询最近一场蜗牛骑士游戏详情 public class queryClosestKnight521 : MonoBehaviour { //返回的(解析后) public ClosestKnight closestKnight; public async Task queryClosestKnight() // 5.2.1 { // 准备请求的头部信息,包含授权令牌 Dictionary head521 = new Dictionary { { "Authorization", Global.global.serverResponse.data.token } }; // 请求体可以为空对象(即 "{}") string requestBody = "{}"; // 异步发送请求以获取最新的蜗牛骑士信息 string response521 = await web.SendRequest(web.URL + "/snail/gameKnight/queryLatest", "POST", requestBody, head521); // 调试输出接收到的响应 Debug.Log("5.2.1查询最近一场蜗牛骑士" + response521); //将响应反序列化为 ClosestKnight 对象 // 将返回的 JSON 字符串反序列化为 ClosestKnight 对象 ClosestKnight closestKnight = JsonConvert.DeserializeObject(response521); //if (closestKnight != null && closestKnight.Data != null) //{ // Debug.Log("携带的秒数: " + closestKnight.Data.CarrySeconds); // Debug.Log("游戏ID: " + closestKnight.Data.GameKnightModel.Id); // Debug.Log("游戏开始时间: " + closestKnight.Data.GameKnightModel.StartTime); // // 遍历房间响应列表 // foreach (var room in closestKnight.Data.GameKnightRoomResponseVoList) // { // Debug.Log("骑士ID: " + room.KnightId); // Debug.Log("马匹编号: " + room.HorseNo); // Debug.Log("马匹用户编号: " + room.HorseUserNo); // Debug.Log("马匹豆币: " + room.HorseBeansCoin); // } //} // 返回解析后的 closestKnight 对象 return closestKnight; } }