麻烦使用班级中的所有成员。为什么我只能使用列表?

时间:2015-05-28 22:59:57

标签: c# class

我有以下类对象结构:

public class StatusObj3
{
    public int status { get; set; }
    public DataObj3 data { get; set; }
}

public class DataObj3
{
    public string survey_id { get; set; }
    public string date_created { get; set; }
    public string date_modified { get; set; }
    public int custom_variable_count { get; set; }
    public List<Custom_VariablesObj> custom_variables { get; set; }
    public int language_id { get; set; }
    public int num_responses { get; set; }
    public int question_count { get; set; }
    public string nickname { get; set; }
    public TitleObj title { get; set; }
    public List<PagesObj> pages { get; set; }
}

public class Custom_VariablesObj
{
    public string variable_label { get; set; }
    public string question_id { get; set; }
}

public class TitleObj
{
    public bool enabled { get; set; }
    public string text { get; set; }
}

public class PagesObj
{
    string page_id { get; set; }
    string heading { get; set; }
    string sub_heading { get; set; }
    public List<QuestionObj> questions { get; set; }
}

public class QuestionObj
{
    public string question_id { get; set; }
    public string heading { get; set; }
    public string position { get; set; }
    public QuestionTypeObj type { get; set; }
    public List<AnswerObj> answers { get; set; }
}

public class QuestionTypeObj
{
    public string family { get; set; }
    public string subtype { get; set; }
}

public class AnswerObj
{
    public string answer_id { get; set; }
    public int position { get; set; }
    public string text { get; set; }
    public string type { get; set; }
    public bool visible { get; set; }
    public int weight { get; set; }
    public bool apply_all_rows { get; set; }
    public bool is_answer { get; set; }
    public List<ItemsObj> items { get; set; }
}

public class ItemsObj
{
    public string answer_id { get; set; }
    public int position { get; set; }
    public string type { get; set; }
    public string text { get; set; }
}

我通过以下方式将json反序列化为此对象:

   var results_SurveyDetails = deserializer.Deserialize<StatusObj3>(json_returned);

我正试图通过以下网页循环:

    foreach (var page in results_SurveyDetails.data.pages)

但是,并非所有页面成员都可以使用。 只有page.questions,而不是page_id,heading和subheading。

我做错了什么?

1 个答案:

答案 0 :(得分:4)

您在班级public的其他媒体资源上遗漏了PagesObj