我正在反序列化一个JSON文件,这是我的Classes结构:
public class ControlInfoDataGroup
{
public string UniqueId { get; private set; }
public ObservableCollection<ControlInfoDataItem> Items { get; private set; }
...
}
public class ControlInfoDataItem
{
public string UniqueId { get; private set; }
public ObservableCollection<ControlInfoDataItem> SubItems { get; private set; }
...
}
然后我用这些代码反序列化我的JSON:
public class JsonFileReader
{
public ObservableCollection<ControlInfoDataGroup> Groups { get; set; }
Groups = new ObservableCollection<ControlInfoDataGroup>();
using FileStream openStream = File.OpenRead(JsonFilePath);
var controlInfoDataGroup = await JsonSerializer.DeserializeAsync<JsonFileReader>(openStream, new JsonSerializerOptions
{
WriteIndented = true,
PropertyNameCaseInsensitive = true
});
}
这是我的json文件内容:
{
"Groups": [
{
"Title": "Home",
"IsSpecialSection": false,
"HideGroup": false,
"IsSingleGroup": false,
"IsExpanded": false,
"Items": [
{
"Title": "Movie",
"IsNew": false,
"IsUpdated": false,
"IsPreview": false,
"HideItem": false,
"HideNavigationViewItem": false,
"HideSourceCodeAndRelatedControls": false,
"IncludedInBuild": false
}
],
"InfoBadge": null
}
]
}
我只得到“家”和这个项目没有任何“项目”,但根据我的json文件,我有一个项目的“家”称为“电影”.问题在哪里?我怎么能解决它?
1条答案
按热度按时间owfi6suc1#
你有奇怪的类,试试这些