using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using UnityEngine; public class querySubjectList : MonoBehaviour { // 创建请求头,使用最新的 token public Dictionary CreateHeaders() { if (string.IsNullOrEmpty(Global.global.loginResponse.data.access_token)) { Debug.LogWarning("尝试创建请求头时,token 未设置。"); return new Dictionary(); } return new Dictionary { { "Authorization","Bearer "+Global.global.loginResponse.data.access_token }, {"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" } }; } //查询演练科目信息列表 public async void QueryDrillSubject() { string response = await web.SendRequest(web.URL + "/game/subject/list", "GET", "", CreateHeaders()); Debug.Log("查询演练科目信息列表: " + response); // 使用 Newtonsoft.Json 进行反序列化 DrillSubject drillSubject = JsonConvert.DeserializeObject(response); // 检查反序列化结果 if (drillSubject == null) { Debug.LogError("Failed to deserialize JSON. DrillSubject is null."); return; } if (drillSubject.data == null || drillSubject.data.Count == 0) { Debug.LogWarning("No subjects found in the returned data."); return; } // 遍历反序列化后的 data 列表 foreach (var subject in drillSubject.data) { Debug.Log("ID: " + subject.id); Debug.Log("Scene Names: " + subject.sceneNames); Debug.Log("Name: " + subject.name); Debug.Log("Suit Version: " + subject.suitVersion); Debug.Log("Type: " + subject.type); Debug.Log("Description: " + subject.description); Debug.Log("Price: " + subject.price); Debug.Log("Company ID: " + subject.companyId); Debug.Log("Status: " + subject.status); Debug.Log("Delete Flag: " + subject.delFlag); Debug.Log("Remark: " + subject.remark); Debug.Log("Game Name: " + subject.gameName); Debug.Log("OSS ID: " + subject.ossId); Debug.Log("File List: " + subject.fileList); // 如果需要进一步处理字段,可以在这里进行 // 比如,将价格转换为数字计算,或根据特定类型执行逻辑 } } }