本文介绍了如何反序化这个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Serilize func我做得正确我认为

Serilize func i did correctly i think

public void Save1(Items objectToSave, string objectIndexKey, string objectIndexKeyFormat) { ApplicationDataContainer appSettings =ApplicationData.Current.LocalSettings; int index = this.GetNextIndex(objectIndexKey); string key = new StringBuilder().AppendFormat(objectIndexKeyFormat, index).ToString(); if (CanSaveObject(objectToSave)) { XmlSerializer xmlIzer = new XmlSerializer(typeof(Items)); var writer = new StringWriter(); xmlIzer.Serialize(writer, objectToSave); if (appSettings.Values.ContainsKey(key)) { //appSettings.Values[key] = objectToSave; appSettings.Values[key] = writer.ToString(); } else { // appSettings.Values.Add(key, objectToSave); appSettings.Values.Add(key, writer.ToString()); }

}

}

Deserilize function

Deserilize function

 public void GetSavedSearches()
         {
             string key = string.Empty;
             ApplicationDataContainer appSettings = Windows.Storage.ApplicationData.Current.LocalSettings;


 XmlSerializer xmlIzer = new XmlSerializer(typeof(Items));
             XmlReader reader = XmlReader.Create(appSettings.Values.ToString());
             Items myList = new Items();
             myList = (xmlIzer.Deserialize(reader)) as Items;
             var objectToSave1 = (Items)xmlIzer.Deserialize(reader);
}

我没有得到如何反序列化这个。 我使用MVVM模式。

I m not getting how to deserialize this one.  I m using MVVM pattern.

GetSavedSearches() and save1() both are in abcviewmodel.cs

和我打电话 来自视图的GetSavedSearches()意味着已保存的.xaml.cs。 任何人都可以帮助我。

and i m calling  GetSavedSearches() from view means savedseach.xaml.cs.  Can any one help me.

推荐答案

如果
appSettings ContainsKey key ))
{

if(appSettings.Values.ContainsKey(key)){

appSettings.Values [ key ]。Values.ToString();

appSettings.Values[key].Values.ToString();

//然后使用XmlSerializer反序列化上面的字符串。

// and then use XmlSerializer to deserialize the above string.

}

或迭代设置集合中的每个值,看看字符串是否可以反序列化为xml
,如果是,则逐个反序列化。


Or iterate over each value in setting collection and see if string can be deserialized to xml and if yes then deserialize them one by one.




这篇关于如何反序化这个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 13:43