由于$id、$ref等是默认Json.NET的特殊属性,在反序列化时不会将其对应的值填充,例如:

[DataContract]
public class MyObject
{
    [DataMember(Name = "$id")]
    public string Id { get; set; }
}

这个时候可以通过自定义JsonSerializerSettings将MetadataPropertyHandling设置为Ignore,例如:

public static T DeserializeObject<T>(String value)
{
    return JsonConvert.DeserializeObject<T>(value, new JsonSerializerSettings()
    {
        MetadataPropertyHandling = MetadataPropertyHandling.Ignore
    });
}

 

相关文章:

  • 2022-12-23
  • 2022-02-23
  • 2018-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-30
  • 2021-07-08
  • 2021-06-02
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案