94 lines
3.1 KiB
C#
94 lines
3.1 KiB
C#
using Newtonsoft.Json;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using UnityEngine;
|
||
|
||
public class querySubjectList : MonoBehaviour
|
||
{
|
||
|
||
// 创建请求头,使用最新的 token
|
||
public Dictionary<string, string> CreateHeaders()
|
||
{
|
||
|
||
|
||
if (string.IsNullOrEmpty(MyGlobal.global.loginResponse.data.access_token))
|
||
{
|
||
Debug.LogWarning("尝试创建请求头时,token 未设置。");
|
||
return new Dictionary<string, string>();
|
||
}
|
||
|
||
return new Dictionary<string, string>
|
||
{
|
||
{ "Authorization","Bearer "+MyGlobal.global.loginResponse.data.access_token },
|
||
{"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" }
|
||
};
|
||
}
|
||
//查询演练科目信息列表
|
||
public async Task<DrillSubject> QueryDrillSubject()
|
||
{
|
||
string response = await web.SendRequest(web.URL + "/game/subject/list", "GET", "", CreateHeaders());
|
||
Debug.Log("查询演练科目信息列表: " + response);
|
||
|
||
// 使用 Newtonsoft.Json 进行反序列化
|
||
DrillSubject drillSubject = JsonConvert.DeserializeObject<DrillSubject>(response);
|
||
|
||
// 检查反序列化结果
|
||
if (drillSubject == null)
|
||
{
|
||
Debug.LogError("Failed to deserialize JSON. DrillSubject is null.");
|
||
}
|
||
|
||
if (drillSubject.data == null || drillSubject.data.Count == 0)
|
||
{
|
||
Debug.LogWarning("No subjects found in the returned data.");
|
||
}
|
||
|
||
// 遍历反序列化后的 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);
|
||
// 如果需要进一步处理字段,可以在这里进行
|
||
// 比如,将价格转换为数字计算,或根据特定类型执行逻辑
|
||
}
|
||
return drillSubject;
|
||
}
|
||
}
|
||
//=======================================================================================================
|
||
public class DrillSubject : Response
|
||
{
|
||
[JsonProperty("data")]
|
||
public List<QueryDrillSubjectData> data; // 确保字段名与 JSON 中的匹配
|
||
}
|
||
|
||
public class QueryDrillSubjectData
|
||
{
|
||
public string id;//
|
||
public string[] sceneIds;
|
||
public string sceneNames;
|
||
public string name;
|
||
public string suitVersion;
|
||
public string type;
|
||
public string description;
|
||
public string price;
|
||
public string companyId;
|
||
public string status;
|
||
public string delFlag;
|
||
public string remark;
|
||
public string gameName;
|
||
public string ossId;
|
||
public string fileList;
|
||
} |