我已经try 了Stackoverflow上描述的一些解决方案(例如Best way to deserialize a nested list in a json - C#).
我已经试过了,但对我不起作用.也许我在什么地方弄错了.
以下是我用来执行HTTP请求的代码:
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.PostAsync(url, someData);
response.EnsureSuccessStatusCode();
string responseString = response.Content.ReadAsStringAsync().Result;
AllChapters allChapters = JsonConvert.DeserializeObject<AllChapters>(responseString);
但是当我运行我的代码时,即使responseString
中有数据,allChapters
也总是为空(NULL).你们中有谁有解决这个问题的办法吗?我可能遗漏了一些东西,但我不知props 体是什么.
这是我的responseString
美元的样子:
{
"AllChapters": [
{
"ChapterIndex": 1,
"ChapterParagraphs": [
{
"ParagraphIndex": 1,
"Text": "SomeText"
}
],
"Title": "First Chapter"
},
{
"ChapterIndex": 2,
"ChapterParagraphs": [
{
"ParagraphIndex": 1,
"Text": "SomeText"
},
{
"ParagraphIndex": 2,
"Text": "SomeText"
}
],
"Title": "Second Chapter"
}
]
}
我已经创建了三个类来存储数据:
100
public class AllChapters
{
public List<OneChapter> OneChapter { get; set; }
}
100
public class OneChapter
{
public int ChapterIndex { get; set; }
public List<ChapterParagraph> ChapterParagraphs { get; set; }
public string Title { get; set; }
public OneChapter()
{
ChapterIndex = 0;
ChapterParagraphs = new List<ChapterParagraph>;
Title = string.empty;
}
}
100
public class ChapterParagraph
{
public int ParagraphIndex { get; set; }
public string Text { get; set; }
public ParagraphScore()
{
ParagraphIndex = 0;
Text = string.Empty;
}
}