我在此頁面上教程http://channel9.msdn.com/Series/Windows-Phone-8-1-Development-for-Absolute-Beginners/Part-22-Storing-and-Retrieving-Serialized-Data,因爲我想讓我的應用程序將數據存儲在JSON文件中,然後再讀取它。關於教程的2件事:無法讀取JSON文件 - FileNotFoundException
我按寫按鈕 - 工作正常,然後按讀按鈕,它也可以,但是,我關閉win手機8.1模擬器,再次打開它,按讀取按鈕,我得到了An exception of type 'System.IO.FileNotFoundException'exception!
爲什麼是的,我應該從以前運行的應用程序已經在磁盤上的文件?或者當我關閉仿真器時它會被擦除嗎?此外,我查找磁盤上的指定文件,無法找到它!任何幫助?
private const string JSONFILENAME = "data.json";
private async Task readJsonAsync()
{
string content = String.Empty;
var myStream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(JSONFILENAME);
using (StreamReader reader = new StreamReader(myStream))
{
content = await reader.ReadToEndAsync();
}
resultTextBlock.Text = content;
}
private async Task writeJsonAsync()
{ // Notice that the write is ALMOST identical ... except for the serializer.
var myCars = buildObjectGraph();
var serializer = new DataContractJsonSerializer(typeof(List<Car>));
using (var stream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(
JSONFILENAME,
CreationCollisionOption.ReplaceExisting))
{
serializer.WriteObject(stream, myCars);
}
resultTextBlock.Text = "Write succeeded";
}
請格式化您的代碼。 – 2014-09-29 18:07:36
對不起,用過報價! – Dodi 2014-09-29 18:12:54