【问题标题】:How to access the Root member of Object如何访问对象的根成员
【发布时间】:2019-12-07 06:52:44
【问题描述】:

我目前有这样的东西

object t = JsonConvert.DeserializeObject(mystring);

现在,当我浏览它时,它有一个属性“Root”,其中包含我需要的字符串。我如何访问该属性?

【问题讨论】:

    标签: c# json object


    【解决方案1】:

    您可以简单地使用POCO 类:

    public class Poco
    {  
        [JsonProperty("Root")]
        public string Root { get; set; }
    }
    

    然后您可以deserialize your JSON to this specified type 并访问他们的属性,如下所示:

    var root = (JsonConvert.DeserializeObject<Poco>(mystring)).Root;
    

    【讨论】:

      猜你喜欢
      • 2013-12-30
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 2013-02-19
      相关资源
      最近更新 更多