有效负载进入parts.model,它被称为Dynamic,因为它是一个由多个端点使用的服务。因此,我试图保留结构,同时试图解决ValueKind = Object问题。
这就是我试图转换回动态的模型。
"Model": {
"CustomerSurname": "Johnson",
"Title": "Mr",
"PlanType": "Help Extension",
"ServiceAdvisor": "Jeff Matle",
"DealershipName": "Goldwagen Pretoria"
},
我尝试使用JsonSerializer.Deserialize多次,但它不起作用。
public async Task<IActionResult> SendSms([FromBody] CreatePart parts)
{
parts.DateMessageScheduled = DateTime.Now;
parts.DateCutOff = DateTime.MaxValue;
parts.CommunicationTypeId = CommunicationType.Codes.SMS;
dynamic obj = parts.Model;
JsonElement jsonString = obj;
var dynamicObject = JsonSerializer.Deserialize<JsonElement>(jsonString);
var result = await _createNewPartService.Post(parts);
return new JsonResult(result);
}
dynamicObject的结果:
ValueKind = Object : "{
"CustomerSurname": "Johnson",
"Title": "Mr",
"PlanType": "Help Extension",
"ServiceAdvisor": "Jeff Matle",
"DealershipName": "Goldwagen Pretoria"
}"
1条答案
按热度按时间erhoui1w1#
试试这个代码
但正如@Dai在评论中所写的那样,“仅仅因为你能做到这一点,并不意味着你应该这样做”