要求使用nodejs或C#写一个请求参数为如下格式的接口。
请求为post ,参数为body中raw,只要能拿到三个值即可。如下为参数:
{
"data": "{\"LightweightName\":\"SS\",\"status\":\"0\",\"Msg\":\"\"}"
}
{
"data": "{\"LightweightName\":\"SS\",\"status\":\"0\",\"Msg\":\"\"}"
}
使用System.Text.Json
或者Newtonsoft.Json
将POST请求中的data
反序列化成对应的对象即可,.NET 6(C#)的实现示例如下:
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace RequestRawDemo.Controllers
{
[ApiController]
[Route("[controller]/[action]")]
public class UploaderController : ControllerBase
{
[HttpPost]
public LightWeight? Upload([FromBody] LightWeightRequest request)
{
return request.LightWeight;
}
}
public class LightWeightRequest
{
public string? Data { get; set; }
public LightWeight? LightWeight => Data != null ? JsonConvert.DeserializeObject<LightWeight>(Data) : new LightWeight();
}
public class LightWeight
{
public string? LightweightName { get; set; }
public string? Status { get; set; }
public string? Msg { get; set; }
}
}
运行效果如下: