_xiaofang/xiaofang/Assets/Script/DirllInterface/querySenceList.cs

105 lines
3.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
public class querySenceList : MonoBehaviour
{
// 创建请求头,使用最新的 token
public Dictionary<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(Global.global.loginResponse.data.access_token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization","Bearer "+Global.global.loginResponse.data.access_token },
{"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" }
};
}
//查询场景信息列表
public async Task<QuerySceneData> QueryScene()
{
// 发送请求并获取返回数据
string response = await web.SendRequest(web.URL + "/game/scene/list", "GET", "", CreateHeaders());
Debug.Log("查询场景信息列表" + response);
// 使用Newtonsoft.Json来反序列化JSON数据到QuerySceneData对象
QuerySceneData senceData = JsonConvert.DeserializeObject<QuerySceneData>(response);
// 打印整体响应数据的某些属性
if (senceData != null && senceData.data != null)
{
foreach (var scene in senceData.data)
{
Debug.Log("场景ID: " + scene.id);
Debug.Log("场景名称: " + scene.name);
Debug.Log("描述: " + scene.description);
Debug.Log("价格: " + scene.price);
Debug.Log("行业: " + scene.industryName);
if (scene.fileList != null)
{
foreach (var file in scene.fileList)
{
Debug.Log("文件名称: " + file.name);
Debug.Log("文件URL: " + file.url);
}
}
}
}
else
{
Debug.Log("解析服务器数据失败");
}
return senceData;
}
}
//============================================================================
// 根数据类
public class QuerySceneData
{
public int code { get; set; }
public string msg { get; set; }
public List<Scene> data { get; set; }
}
// 场景信息类
public class Scene
{
public string id { get; set; }
public string name { get; set; }//场景名称
public string type { get; set; }//场景类型
public string description { get; set; }//场景描述
public int suitIndustry { get; set; }//适用行业
public string price { get; set; }//价格 分
public int companyId { get; set; }//单位(**小学之类)
public string status { get; set; }//场景状态0启用1停用
public string delFlag { get; set; }
public string remark { get; set; }
public string gameName { get; set; }
public string gameType { get; set; }
public string ossId { get; set; }
public List<File> fileList { get; set; }
public string gameStoreroom { get; set; }
public string industryName { get; set; }
public string companyName { get; set; }
}
// 文件信息类
public class File
{
public string ossId { get; set; }
public string name { get; set; }
public string url { get; set; }
public string originalName { get; set; }
public string fileSuffix { get; set; }
}