[英]How to post multiple object data json in web api in one controller
i have json data example this : 我有json数据示例如下:
{
"datetime": "2019-07-31 15:40:01",
"Kursi": [
{
"kursi_id": 23,
"kursi_value": 100
}
],
"Bunga": [
{
"bunga_id": 3,
"bunga_value": "894,9"
}
]
}
how im supposed to do. 我应该怎么做。 i want to post this json into my db sql server in one controller.
我想将此json发布到一个控制器中的db sql服务器中。 but i have no idea if the data have two object "Kursi" and "Bunga" ?
但我不知道数据中是否有两个对象“ Kursi”和“ Bunga”?
If you want to post data to the controller, create a model that represents you json. 如果要将数据发布到控制器,请创建一个代表您json的模型。
public class MyModel
{
public DateTime datetime { get; set; }
public List<Kursi> Kursi { get; set; }
public List<Bunga> Bunga { get; set; }
}
public class Kurski
{
public int kursi_id { get; set; }
public int kursi_value { get; set; }
}
public class Bunga
{
public int bunga_id { get; set; }
public string bunga_value { get; set; }
}
Please, do read the documentation . 请阅读文档 。 It is not as hard as it looks, and it pays off the hard work.
它并不像看起来那么难,而且还付出了辛勤的工作。
By the way, ASP.NET Core is an alternative to Web API. 顺便说一下,ASP.NET Core是Web API的替代方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.