Hi @Omkar Mhaiskar ,
You could refer to the following method to accept the data from the request body.
- Based on the json string to create a model and get the data via the model. For example, according to the json string to create a JsonResultModel model
Then, in the API post method, set it as the parameter:public class JsonResultModel { public List<Datum> data { get; set; } public List<Included> included { get; set; } } public class Attributes { public string title { get; set; } public string body { get; set; } public string name { get; set; } } public class Datum { public string type { get; set; } public string id { get; set; } public Attributes attributes { get; set; } } public class Included { public string type { get; set; } public string id { get; set; } public Attributes attributes { get; set; } }
The result is like this:[HttpPost] public void Post([FromBody] JsonResultModel result) { }
- Transfer the json string as a string type parameter. The API post method is like this:
When calling the API via swagger, the parameter is a string value.[HttpPost] public void Post([FromBody] string result) { }
"{\"data\":[{\"type\":\"articles\",\"id\":\"1\",\"attributes\":{\"title\":\"JSON:APIpaintsmybikeshed!\",\"body\":\"Theshortestarticle.Ever.\"}}],\"included\":[{\"type\":\"people\",\"id\":\"42\",\"attributes\":{\"name\":\"John\"}}]}"
The result is like this:Then, in the Post method, you can deserialize the json string to the object
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion