【发布时间】:2020-06-06 02:46:47
【问题描述】:
每当我运行这个程序时,JSON 可视化器都会显示所有 JSON 都是从 url 读取的,但是它一直说在反序列化对象后发现了额外的文本。
我的主要目标是能够读取 JSON 并将其添加到某种数据集中以便我可以显示它
public class Wrapper
{
[JsonProperty("results")]
public DataSet DataSet { get; set; }
}
public class Rootobject
{
public int response_code { get; set; }
public Result[] results { get; set; }
}
public class Result
{
public string category { get; set; }
public string type { get; set; }
public string difficulty { get; set; }
public string question { get; set; }
public string correct_answer { get; set; }
public string[] incorrect_answers { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string json = (new WebClient()).DownloadString("https://opentdb.com/api.php?amount=10&type=boolean");
DataSet ds = JsonConvert.DeserializeObject<Wrapper>(json).DataSet;
}
}
}
}
【问题讨论】:
-
你从不使用 Rootobject
-
我对编码还很陌生,并且刚刚通过我在网上找到的示例进行了查看。我应该如何使用 Rootobject?
-
用
Rootobject rootObject替换DataSet DataSet