C# 将JSon属性映射到JSon字符串内的变量?

C# 将JSon属性映射到JSon字符串内的变量?,c#,json,web-services,json.net,deserialization,C#,Json,Web Services,Json.net,Deserialization,我正在寻找一种使用newtonsoft将多个属性映射到JSon字符串的不同“部分”的方法 我目前拥有的是以下内容(根本不起作用,但也许你会更好地了解我想要实现的目标): 而对应的JSon字符串的结构可能如下所示: { "this" : { "is" : { "an" : { "example" : "this is the first value I want to return" } "another" : "this is

我正在寻找一种使用newtonsoft将多个属性映射到JSon字符串的不同“部分”的方法

我目前拥有的是以下内容(根本不起作用,但也许你会更好地了解我想要实现的目标):

而对应的JSon字符串的结构可能如下所示:

{
  "this" :
  {
    "is" : {
      "an" : {
        "example" : "this is the first value I want to return"
      }
      "another" : "this is the second value"
    }
  }
}
我希望这样做,以便可以轻松地反序列化以下几个JSon字符串:

example y = JsonConvert.DeserializeObject<example>(x);
//where x is the JSon string shown above and
//y.ex == "this is the first value I want to return"
//y.ex2 == "this is the second value
//Also note that example is the class name of the resulting object
示例y=JsonConvert.DeserializeObject(x);
//其中x是上面显示的JSon字符串,并且
//y、 ex==“这是我要返回的第一个值”
//y、 ex2==“这是第二个值
//还要注意,示例是结果对象的类名
希望你能看到我在努力完成什么。提前感谢你的帮助,任何意见都将不胜感激

注意:


经过一段时间的搜索,我发现了一个类似的问题,但没有得到答案。但也许这会有所帮助。

您可以简单地使用
动态
关键字,而不是编写一些复杂的自定义反序列化代码

string json = @"{""this"":{""is"":{""an"":{""example"":""this is the first value I want to return""}}}}";
dynamic jObj = JObject.Parse(json);
string example = jObj.@this.@is.an.example;

PS:this和is在c#中是保留字,所以我在它们前面使用了
@

我考虑过这一点。不过,我更希望有一个可以反序列化的对象。我这样说是因为我处理的json可能有几十万行长(我不想每次想反序列化时都创建一个对象)刚刚意识到这是我的错(我一直在处理两个类似的反序列化代码,并把它们弄混了)。我编辑了这个问题,以反映我的实际问题。很抱歉!
string json = @"{""this"":{""is"":{""an"":{""example"":""this is the first value I want to return""}}}}";
dynamic jObj = JObject.Parse(json);
string example = jObj.@this.@is.an.example;