作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因为我正在尝试访问 对象值 使用 JsonSerializer.Deserialize 使用调试器。
这是我在下面的结果。
OtpData = ValueKind = Object : "{
"OTP":"3245234",
"UserName":"mohit840",
"type":"SuperAdmin"
}"
当我尝试使用
var Data = JsonSerializer.Deserialize(OtpData)
访问它时它给了我以下错误。
"OTP":"3245234",
"UserName":"mohit840",
"type":"SuperAdmin"
更新:
[AllowAnonymous]
[HttpPost("ValidateOTP")]
public IActionResult ValidOTP(dynamic OtpData)
{
bool Result = false;
var Data = JsonSerializer.Deserialize(OtpData);
if (OtpData.type == "SuperAdmin")
{
Users _Users = _Context.Users.FirstOrDefault(j => j.Username == "");
if (_Users != null)
{
_Users.OTP = OtpData.OTP;
_Users.VerififedOTP = true;
_Context.SaveChanges();
Result = true;
}
}
else
{
Staff _Staff = _Context.Staffs.FirstOrDefault(j => j.Username == "");
if (_Staff != null)
{
_Staff.OTP = OtpData.OTP;
_Staff.VerififedOTP = true;
_Context.SaveChanges();
Result = true;
}
}
return Ok(new { Result = Result });
}
更新 2:
{
"OTP":"3245234",
"UserName":"mohit840",
"type":"SuperAdmin"
}
最佳答案
从新版本的 Asp.net Core 3.0 开始,微软推出了 System.Text.Json,它引入了新的 JsonElement
ValueKind
所以ValueKind
来自 System.Text.Json
图书馆和 JsonConvert
来自 Newtonsoft
图书馆。
解析度 :-
您可能在序列化您可能使用过的对象时混合了库 Newtonsoft.Json
在去污时,您可能使用过 System.Text.Json
或相反亦然。
关于c# - 动态 c# ValueKind = Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63121877/
因为我正在尝试访问 对象值 使用 JsonSerializer.Deserialize 使用调试器。 这是我在下面的结果。 OtpData = ValueKind = Object : "{
此问题特定于 System.Text.Json 命名空间,而不是 Newtonsoft。我正在尝试为我的代码中的某个片段编写单元测试,我遇到以下情况: var objString = JsonSeri
我是一名优秀的程序员,十分优秀!