【发布时间】:2019-05-10 14:23:36
【问题描述】:
我有一个 json 文件,它在根中具有随机名称,但在子元素中具有相同的结构。我想获取数组或列表中的所有子元素。
示例 json 文件:
{
"-LeHl495vL6vh-8CaLbD":{
"apiKey":"sr-tr-137-beea04e44cb452ba0da0ca090b7e61b4ec6ffc69"
},
"-LeHl6jrhUEMb7slZcpB":{
"apiKey":"sr-tr-137-aef7a23095c0c7baef1ef681bdd8bf9756ac2a17"
}
}
我尝试过这些课程,但做不到。
public class RequestedReport
{
public Dictionary<string, List<ReportData>> ReportDatas { get; set; }
}
public class ReportData
{
public string apiKey { get; set; }
}
所以我预期的反序列化输出类似于 List,其中包含 json 文件中的所有 apiKey。
提前致谢。
【问题讨论】:
-
每个对象中有多个
apiKey条目还是只有一个? -
每个节点只有一个api key。
-
乔恩有你的答案:)