此代码it's在C#中的Visual Studio 2012写我使用WinRT的工具包
您好我试图创建此loadGrupos赶上文件grupo.txt阅读并到类Grupos装入他的内容,但我不知道发生what's名单grupos recive从JSON内容,但是当我callend的loadGrupos的可变grupos鸵鸟政策揭露什么。 我真的鸵鸟政策知道what's回事。 我试着调试和我didn't发现任何错误。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Windows.Storage;
using Windows.ApplicationModel;
using WinRTXamlToolkit.IO.Extensions;
using Windows.UI.Popups;
namespace xxx;
public class MyJConverter
{
public String _Path;
//private Windows.ApplicationModel.Package package;
// private Windows.Storage.StorageFolder installedLocation;
private StorageFolder _Folder = Windows.Storage.ApplicationData.Current.LocalFolder;
//KnownFolders.DocumentsLibrary
public MyJConverter() {
// package = Windows.ApplicationModel.Package.Current;
// installedLocation = package.InstalledLocation;
}
public void save(Object obj)
{
_Path = JsonConvert.SerializeObject(obj);
gravandoUmDocumento("data",_Path);
}
public void saveGrupo(Object obj)
{
_Path = JsonConvert.SerializeObject(obj);
gravandoUmDocumento("grupo", _Path);
}
public async void gravandoUmDocumento(String nomeDoArquivo,String menssagem) {
// var _Folder = Windows.Storage.ApplicationData.Current.LocalFolder;
// var _Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
//await menssagem.WriteToFile(nomeDoArquivo + "1.txt", KnownFolders.DocumentsLibrary);
await menssagem.WriteToFile(nomeDoArquivo + ".txt", _Folder);
}
private List<Ano> anos;
public List<Ano> load()
{
leituraDeUmArquivo("data").Wait();
if (anos != null)
{
return anos;
}
return null;
}
private List<Grupos> grupos;
public List<Grupos> Grupos
{
get { return grupos; }
set { grupos = value; }
}
public List<Grupos> loadGrupos()
{
leituraDeUmArquivo("grupo").Wait();
{
if (grupos != null)
{
return grupos;
}
else
return null;
}
}
public async Task leituraDeUmArquivo(String arquivoASerLido)
{
String leitura = "";
//leitura do data
try
{
// settings
var _Path =arquivoASerLido + ".txt";
// acquire file
var _File = await _Folder.GetFileAsync(_Path);
// read content
leitura = (String) await Windows.Storage.FileIO.ReadTextAsync(_File);
// leitura = (String)_ReadThis;
}
catch {
// leituraDeUmArquivo(arquivoASerLido);
}
if (leitura != "")
{
if (arquivoASerLido.Equals("data"))
{
try
{
anos = JsonConvert.DeserializeObject<List<Ano>>(leitura);
}
catch {
}
}
if (arquivoASerLido.Equals("grupo"))
{
try{
grupos = JsonConvert.DeserializeObject<List<Grupos>>(leitura);
}
catch { }
}
}
}
}
HI我做你建议更换的修改,但问题didn't解决,使我后我的所有代码。 我真的didn't发现为什么WinRT中不容加载该文件,一段时间内拿下8负载有时无。 现在,随着modificiations应用程序块干什么去了前面。
如果我去调试可视找到该文件,如果我只运行没有。