我在此页面上教程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