本文介绍了如何在 Windows Phone 8 中创建一个空的 xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我正在像这样在我的 WP8 应用程序中创建一个空的 xml 文件
I'm creating an empty xml file in my WP8 app like this
public static bool create()
{
Dictionary<string, object> __data = new Dictionary<string, object>();
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Data.xml", FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<DataModel>));
using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
{
serializer.Serialize(stream, __data);
}
}
}
return true;
}
但是我在 serializer.Serialize(stream, __data);
我做错了什么?
编辑:我在创建新字典后添加了这一行 __data.Add("testkey", "testdatavalue");
但我仍然遇到相同的异常.
Edit: I added this line after creating the new dictionary __data.Add("testkey", "testdatavalue");
but I still get the same exception.
推荐答案
我们有
Dictionary<string, object> __data = ...
XmlSerializer serializer = new XmlSerializer(typeof(List<DataModel>));
serializer.Serialize(stream, __data);
所以你的序列化器是用于另一种类型(DataModel
).它不会处理 Dictionary<>
.
So your serializer is for another Type (DataModel
). It won't handle a Dictionary<>
.
这篇关于如何在 Windows Phone 8 中创建一个空的 xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论