【发布时间】:2016-07-11 19:07:57
【问题描述】:
我正在使用 Json 文件为我的应用程序进行本地存储。在使用 Visual Studio 的模拟器读取和写入文件时,可以正常工作。当我连接设备并尝试在该设备上运行时,我无法访问我的 Json 文件。
我的 json 文件总是设置为内容和复制。
这是我读取文件的尝试语句。我尝试了两种访问文件Current.InstalledLocation 和Uri("ms-appx:///) 的主要方法。两者似乎都可以在模拟器中工作,但都不能在设备上工作。
try
{
var package = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder folder = await package.GetFolderAsync("Data");
StorageFile file = await folder.GetFileAsync("Users.json");
//Uri dataUri = new Uri("ms-appx:///Data/Users.json");
//StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
string jsonText = await FileIO.ReadTextAsync(file);
JsonArray jsonArray = JsonArray.Parse(jsonText);
foreach (JsonValue userValue in jsonArray)
{
//Build my model object out of json
}
}
catch(Exception e)
{
//Creating instance for the MessageDialog Class
//and passing the message in it's Constructor
MessageDialog msgbox = new MessageDialog(e.Message);
//Calling the Show method of MessageDialog class
//which will show the MessageBox
await msgbox.ShowAsync();
}
输出窗口显示:
Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll
Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll
编辑: try catch 循环没有捕获与文件系统访问问题相关的异常。
在启动时单步执行我在StorageFile file = await folder.GetFileAsync("Users.json"); 失败
为什么我通过我在string jsonText = await FileIO.ReadTextAsync(file);失败的按钮触发该功能
我希望运行我的应用程序的设备正在运行 Windows Embedded 8.1 Handheld update 2(它是 ToughPad Panazonic FZ-E1)。我是否需要针对 windows 8.1 而不是 windows phone 8.1?直到此时控制 POS 条码扫描仪为止,它一直可以与手机一起正常工作。
任何帮助将不胜感激我不知所措。我的问题可能是由设备上的设置引起的吗?
【问题讨论】:
-
不只是消息,能否分享一下异常的完整
ToString()输出,包括异常类型、消息和回溯? -
经过检查,我的 try catch 块甚至没有捕获异常。我看到的异常不知何故来自函数的下方。除了将我踢出断点步骤之外,mscorlib 异常似乎没有引起任何问题。
标签: c# asp.net json windows-phone-8.1 windows-embedded-8.1