JsonConvert.DeserializeObject不适用于1个特定对象(“ $ id”)返回null为空[重复]

问题描述 投票:0回答:1

这是我的模特:

 public class Object
 {
     [JsonProperty(PropertyName = "test1")]
     public string Test1 { get; set; }

     [JsonProperty(PropertyName = "test2")]
     public string Test2 { get; set; }

     [JsonProperty(PropertyName = "_id")]
     public ID Id { get; set; }
 }

 public class ID
 {
     [JsonProperty(PropertyName = "$id")]
     public string Id { get; set; }
 }

当调试时,它会正确显示每个值,但在JsonConvert之后。 ID为空。我在这里错了吗?

Json身体:

 "test1: "sometext",
 "test2": "sometext",
  "_id": {
    "$id": "thisisanidstring"
  }
c# json json.net json-deserialization
1个回答
0
投票

This question is already there看看。

Json.NET使用$ id作为保留字来帮助它处理对象引用。

© www.soinside.com 2019 - 2024. All rights reserved.