[英]Posting Complex JSON Data in .NET Core WebAPI Project
I need to read json data which is posted by client pay load to my API is something like below:我需要阅读由客户端负载发布到我的 API 的 json 数据,如下所示:
{
"result": {
"destinationId":"003",
"message":"msg",
"sourceEntityId":"1",
"status":"0"
}
}
My HttpPost
code is something like below:我的
HttpPost
代码如下所示:
public ActionResult Post([FromBody] clsTicketinfo ticketInfo)
{
// Some Code
}
Please help me to read this json data in my HttpPost
method.请帮助我在我的
HttpPost
方法中阅读此 json 数据。 Also how to read the headers data which is sent by client along with post request.还如何读取客户端连同发布请求一起发送的标头数据。
Your clsTicketinfo
class should look like this您的
clsTicketinfo
class 应该如下所示
public class clsTicketInfo
{
public Result result { get; set;} // <- add this line
public string affectedCIs {get; set;}
public string affectedLocations {get; set;};
public string assignedToGroup {get; set;};
// lot of other fields with property defined
}
And you should create another class with the name Result
or whatever you want, as below:您应该创建另一个 class 名称为
Result
或任何您想要的名称,如下所示:
public class Result
{
public string destinationId { get; set; }
public string message { get; set; }
public string sourceEntityId { get; set; }
public string status { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.