我正在访问服务器并获取一些数据,正在解析这些数据并将其存储在 Dictionary<TKey, TValue>
中。
我将此 Dictionary<TKey, TValue>
列表存储在独立存储中。现在,问题是每当我尝试检索 Dictionary<TKey, TValue>
(在第二次运行中)我在第一次运行中存储的内容时,bean 中每个键的值都会变为空。我不知道存储 Dictionary<TKey, TValue>
的方式是否错误。
代码示例:
CacheManager.getInstance().PersistData(CacheManager.SERVICE_TABLE,
dictionaryList);
public void PersistData(string storageName, object dict)
{
try
{
PersistDataStore.Add(storageName, dict);
PersistDataStore.Save();
}
catch (Exception ex)
{
}
}
最佳答案
我得到了问题的解决方案,字典dict的成员必须序列化。 IE。,
using System.Runtime.Serialization;
[DataContact]
public class classname()
{
[datamember]
public int propertyname;
}
关于c# - 在独立存储中存储 Dictionary<TKey, TValue>,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7569112/