如何从嵌套对象获取属性?

时间:2019-04-17 19:43:10

标签: c# asp.net arrays nested json.net

我是C#语言的新手,我具有json数据并转换为c#对象,但是我想从Response模型和注释中获取嵌套属性,并且从Response类获取所有数据,我也需要使用foreach循环从响应类获取数据

public class Response
{
    public string comments { get; set; }
    public string createDate { get; set; }
    public string status { get; set; }
    public string updateDate { get; set; }
}

public class Reviewer
{
    public string displayName { get; set; }
    public string oneAccountId { get; set; }
}

public class Vehicle
{
    public string make { get; set; }
    public string model { get; set; }
    public string vin { get; set; }
    public string year { get; set; }
}

public class ShopReview
{
    public string comments { get; set; }
    public string compCode { get; set; }
    public string createDate { get; set; }
    public string id { get; set; }
    public int rating { get; set; }
    public Response response { get; set; }
    public Reviewer reviewer { get; set; }
    public string status { get; set; }

}

public class RootObject
{
    public string message { get; set; }
    public ShopReview[] shopReviews { get; set; }
}

我尝试使用此代码

   if (review.Response != null)
  {
     foreach (var shopResponse in review.Response)
     {
     CarReviewReply tmpReply = new CarReviewReply();
      {
      Comments = shResponse.Comments,
      LastUpdated = shopResponse.UpdateDate,
      ResponseDate = shopResponse.CreateDate,
      Status = shopResponse.Status
      };
  }
}

我收到错误消息“不包含'GetEnumerator'的公共实例定义”

0 个答案:

没有答案