私はWindows phoneの初心者です。ファイルからの辞書の書き込みと読み取りに成功しました。しかし、私はファイルからネストされた辞書を読み取ることに固執していました。
- メイン辞書
- ログイン(キー),辞書(値)`
- 検証(キー)、辞書(値)
- メイン辞書
共通辞書の下にあるこれらの値をファイルに書き込む必要があり、同じファイルから読み取る必要もあります。どんな助けでも。
前もって感謝します
私はWindows phoneの初心者です。ファイルからの辞書の書き込みと読み取りに成功しました。しかし、私はファイルからネストされた辞書を読み取ることに固執していました。
共通辞書の下にあるこれらの値をファイルに書き込む必要があり、同じファイルから読み取る必要もあります。どんな助けでも。
前もって感謝します
辞書をXMLシリアル化する方法で説明されているようにXmlSerializerを使用できます。http://huseyint.com/2007/12/xml-serializable-generic-dictionary-tipi/のサンプルコードを参照しています(英語ではありませんが、コードは役に立ちます)。
私は解決策を得ました........
public Dictionary FileRead(string Key) { Dictionary > FileResponse = 新しい Dictionary>(); Dictionary ReturnDictionary = new Dictionary(); { using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fileReader = new IsolatedStorageFileStream(DisplayMessage.Storage_Directory,FileMode.Open, FileAccess.ReadWrite, isolatedStorage)) { DataContractSerializer datacontract = new DataContractSerializer(typeof(Dictionary>)) ; FileResponse = (辞書>)datacontract.ReadObject(fileReader); ReturnDictionary = FileResponse[キー]; } } } catch (例外例) { } return (ReturnDictionary); }
public void FileWrite(string Key,Dictionary<string, string> FiletoStore)
{
try
{
using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
Dictionary<string, Dictionary<string, string>> StoredDictionary = new Dictionary<string, Dictionary<string, string>>();
if (!isolatedStorage.FileExists(DisplayMessage.Storage_Directory))
{
using (IsolatedStorageFileStream IsolatedfileStream = new IsolatedStorageFileStream(DisplayMessage.Storage_Directory, FileMode.OpenOrCreate, isolatedStorage))
{
DataContractSerializer datacontract = new DataContractSerializer(typeof(Dictionary<string, Dictionary<string, string>>));
StoredDictionary.Add(Key, FiletoStore);
datacontract.WriteObject(IsolatedfileStream, StoredDictionary);
IsolatedfileStream.Close();
}
}
else
{
using (IsolatedStorageFileStream IsolatedfileStream = new IsolatedStorageFileStream(DisplayMessage.Storage_Directory, FileMode.Open, isolatedStorage))
{
DataContractSerializer datacontract = new DataContractSerializer(typeof(Dictionary<string, Dictionary<string, string>>));
StoredDictionary.Add(Key, FiletoStore);
datacontract.WriteObject(IsolatedfileStream, StoredDictionary);
IsolatedfileStream.Close();
}
}
}
}
catch (Exception ex)
{
}
}