_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/MallSystem2/productInfo22.cs
2024-11-28 05:52:04 +08:00

54 lines
1.8 KiB
C#

using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
public class productInfo22 : MonoBehaviour
{
//public async Task<MallResponsePro> getMallList(int productType, int pageNo, int pageSize)
public async Task<getProductResponse> productInfo(int productId)
{
// 准备请求的头部信息,包含授权令牌
Dictionary<string, string> head22 = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
// 请求体
getProdectBody getProdectBody = new getProdectBody
{
productId = productId,
};
Debug.Log("====入参====" + JsonConvert.SerializeObject(getProdectBody));
// 异步发送请求
string response22 = await web.SendRequest(web.URL + "/snail/product/info", "POST", JsonConvert.SerializeObject(getProdectBody), head22);
// 调试输出接收到的响应
Debug.Log("2.2商品详情:=============== " + response22);
getProductResponse getProductResponse1 = new getProductResponse();
try
{
// 将 JSON 字符串反序列化为 MallResponse 对象
getProductResponse1 = JsonConvert.DeserializeObject<getProductResponse>(response22);
// 判空:首先检查 getProductResponse 和 getProductResponse.data 是否为 null
if (getProductResponse1 != null && getProductResponse1.Data != null && getProductResponse1.Data != null)
{
Debug.Log("8=========D"+getProductResponse1.Data.ProductId);
}
else
{
Debug.LogWarning("响应数据为空或格式错误");
}
}
catch (Exception ex)
{
Debug.LogError("反序列化响应失败: " + ex.Message);
}
return getProductResponse1;
}
}