我正在尝试在 C# 中使用类似字符串列表的东西。数据格式:科名:树木价值:[香蕉、印楝、木瓜、椰子]====科名:动物值:[猫、狗、猪、虎狮]我试过的代码:[DataContract(Name = "FamilyValuesMap", Namespace = "")] public class FamilyValuesMap { [DataMember(Name = "FamilyName", Order = 1)] public string FamilyName { get; set; } [DataMember(Name = "Values", Order = 2)] public List<string> Values { get; set; } } [CollectionDataContract(Name = "FamilyValuesMaps", ItemName = "FamilyValuesMap", Namespace = "")] public class FamilyValuesMaps : List<FamilyValuesMap> { }在下面的代码中,我试图将条目推送到 FamilyValuesMaps,var FamilyValuesMaps = new FamilyValuesMaps();FamilyValuesMaps.Add(new FamilyValuesMap { FamilyName = "Trees", Values = { "Banana", "Neem", "Pappaya", "Coconut" } });我不确定混乱发生在哪里并且代码不起作用它返回以下错误。Data: {System.Collections.ListDictionaryInternal}HResult: -2147467261HelpLink: nullInnerException: nullMessage: "Object reference not set to an instance of an object."Source: nullStackTrace: nullTargetSite: null任何建议或想法会有所帮助?
1 回答
- 1 回答
- 0 关注
- 500 浏览
添加回答
举报
0/150
提交
取消