[英]How should I declare my class to deserialize the following JSON object?
I'm getting the following as JSON response: 我得到以下作为JSON响应:
string responJsonText =
{
"QuestionMasterData":
[
{"question":"First Name"},
{"question":"Second Name"},
{"question":"Last Name"},
{"question":"Password Field"},
{"question":"Re type password"},
{"question":"Email"},
{"question":"Phone"},
{"question":"Address"},
{"question":"State Zip"},
{"question":"Country"},
{"question":" Lorem Ipsum as their default model text. Many desktop publishing"}
],
"status":1
}
I want to deserialize it to .NET object. 我想将它反序列化为.NET对象。 For this I am trying something like this:
为此,我尝试这样的事情:
QuestionResponseClass response =
JsonConvert.DeserializeObject<QuestionResponseClass >(responJsonText);
And I designed the QuestionResponseClass class as follows 我设计了QuestionResponseClass类,如下所示
public class QuestionResponse
{
public List<string> listQs { get; set; }
public int status { get; set; }
}
Clearly, I am making some mistake while declaring the class. 显然,我在宣布上课时犯了一些错误。 Can anyone tell me what should be the type?
谁能告诉我这个类型应该是什么?
Your object does not match the json: 您的对象与json不匹配:
listQs
should be called QuestionMasterData
or use the matching attribute for specifying field name. listQs
应该被称为QuestionMasterData
或使用匹配属性来指定字段名称。 QuestionMasterData
contains a list of objects with one property of question
and is not a List<string>
. QuestionMasterData
包含一个对象列表,其中一个属性为question
,而不是List<string>
。 status1
should be called status
. status1
应该被称为status
。 Something along: 一些东西:
public class QuestionResponse
{
public List<Question> QuestionMasterData { get; set; }
public int status { get; set; }
}
public class Question
{
public string question { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.