3 回答
TA贡献1830条经验 获得超9个赞
您针对返回的 JSON 的类结构不正确。
将您的 JSON 粘贴到json2csharp.com中时,会生成以下 POCO 类:
public class Config
{
public string QDescription { get; set; }
}
public class Settings
{
public string ForceResponse { get; set; }
public string ForceResponseType { get; set; }
public string Type { get; set; }
}
public class Validation
{
public Settings Settings { get; set; }
}
public class Question1
{
public string DETag { get; set; }
public Config Config { get; set; }
public List<string> COrder { get; set; }
public Validation Validation { get; set; }
}
public class QuestionDefinitions
{
public Question1 Question1 { get; set; }
}
public class RootObject
{
public List<string> QuestionIDs { get; set; }
public QuestionDefinitions QuestionDefinitions { get; set; }
public object NextButton { get; set; }
public bool PreviousButton { get; set; }
}
现在使用上述类作为 JSON 结构的表示,您应该能够将其反序列化为 C# 对象。
以下代码行将使用 NewtonSoft 库来完成:
string json = "your json result";
RootObject result = JsonConvert.DeserializeObject<RootObject>(json);
如果您有 2013 或更高版本,您甚至可以在 Visual Studio 中执行此操作,如下文所述:
TA贡献1934条经验 获得超2个赞
也许您可以使用以下内容:
public class Config
{
public string QDescription { get; set; }
}
public class Settings
{
public string ForceResponse { get; set; }
public string ForceResponseType { get; set; }
public string Type { get; set; }
}
public class Validation
{
public Settings Settings { get; set; }
}
public class Question
{
public string DETag { get; set; }
public Config Config { get; set; }
public List<string> COrder { get; set; }
public Validation Validation { get; set; }
}
public class RootObject
{
public List<string> QuestionIDs { get; set; }
public Dictionary<string, Question> QuestionDefinitions { get; set; }
public object NextButton { get; set; }
public bool PreviousButton { get; set; }
}
TA贡献1825条经验 获得超4个赞
试试这个模型
public class RootObject
{
public List<string> QuestionIDs { get; set; }
public QuestionDefinitions QuestionDefinitions { get; set; }
public object NextButton { get; set; }
public bool PreviousButton { get; set; }
}
public class QuestionDefinitions
{
public Question1 Question1 { get; set; }
public List<string> COrder { get; set; }
public Validation Validation { get; set; }
}
public class Question1 {
public string DETag { get; set; }
public Config Config { get; set; }
}
public class Config {
public string QDescription { get; set; }
}
public class Validation {
public Settings Settings { get; set; }
}
public class Settings
{
public string ForceResponse { get; set; }
public string ForceResponseType { get; set; }
public string Type { get; set; }
}
- 3 回答
- 0 关注
- 151 浏览
添加回答
举报