下载/反序列化JSON文件
本文关键字:文件 JSON 反序列化 下载 | 更新日期: 2023-09-27 18:17:15
我尝试下载并反序列化一个JSON文件。
我有这段代码但是当我运行我的应用程序时,我不下载我的文件
public static async void btnGet_Tap()
{
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
try
{
Uri source = new Uri("http://88.174.101.185:15343/share/CkEtT9llw2BCbmPL/all-cards.json");
StorageFile destinationFile = await localFolder.CreateFileAsync(
"all-cards.json", CreationCollisionOption.GenerateUniqueName);
BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);
System.Diagnostics.Debug.WriteLine("-- Download OK");
// Getting JSON from file if it exists, or file not found exception if it does not
StorageFile storageFile = await localFolder.GetFileAsync("all-cards.json");
string configData = await FileIO.ReadTextAsync(storageFile);
// deserialize back to our product!
System.Diagnostics.Debug.WriteLine(" -- Read OK : " + configData);
RootObject card = JsonConvert.DeserializeObject<RootObject>(configData);
// and show it
System.Diagnostics.Debug.WriteLine("Deserialization OK" + card.meta.patch);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.StackTrace);
}
}
}
My error:
-- Download OK
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
-- Read OK :
A first chance exception of type 'System.NullReferenceException' occurred in App3.exe
at App3.Control.<btnGet_Tap>d__0.MoveNext()
The program '[2364] App3.exe' has exited with code 0 (0x0).
您的服务器给出404响应,因此您实际上没有获得正确的数据。