JsonConvert.PopulateObject无法使用布尔值

时间:2020-03-11 00:48:56

标签: c# .net asp.net-mvc json.net jsonconvert

以下代码不会使用falsetrue属性上映射JsonConvert.PopulateObject。其他属性工作正常。我在做错什么吗?

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; }

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

EmitDefaultValue必须为true