【发布时间】:2020-06-22 22:51:40
【问题描述】:
下面的代码不会使用JsonConvert.PopulateObject 将false 映射到true 属性上。其他属性工作得很好。我做错了吗?
JsonConvert.PopulateObject(json, request);
JSON
{ "EventId": 146282, "Name": "api division 9", "Order": 4, "Description": "test", "Active": false }
Account.cs
[DataContract(Name = "Request", Namespace = "")]
public class ApiCreateDivisionRequest : ApiAuthorizedRequest
{
[DataMember(IsRequired = false, EmitDefaultValue = false)]
public bool Active { get; set; }
【问题讨论】:
-
你需要把
[DataContract(Name = "Request", Namespace = "")]放在上面,复制这个bug。看起来EmitDefaultValue需要为真。如果您将其标记为答案,我会给您。 -
好的,一旦我添加了 DataContract,I was able to reproduce it。
-
似乎有一个issue。
标签: c# .net asp.net-mvc json.net jsonconvert