I am trying to parse data from a json file but I am getting variable outputs(Sometimes right, othertimes nothing). I am pretty much sure it is related with the time needed to parse the file, but having trouble finding out where. Here it is-
public class HspitalVM
{
List<Hspital> hspitalList=null;
public List<KeyedList<string, Hspital>> GroupedHospitals
{
get
{
getJson();
var groupedHospital =
from hspital in hspitalList
group hspital by hspital.Type into hspitalByType
select new KeyedList<string, Hspital>(hspitalByType);
return new List<KeyedList<string, Hspital>>(groupedHospital);
}
}
public async void getJson()
{
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
try
{
StorageFile textFile = await localFolder.GetFileAsync(m_HospFileName);
using (IRandomAccessStream textStream = await textFile.OpenReadAsync())
{
using (DataReader textReader = new DataReader(textStream))
{
uint textLength = (uint)textStream.Size;
await textReader.LoadAsync(textLength);
string jsonContents = textReader.ReadString(textLength);
hspitalList = JsonConvert.DeserializeObject<IList<Hspital>>(jsonContents) as List<Hspital>;
}
}
}
catch (Exception ex)
{
string err = "Exception: " + ex.Message;
MessageBox.Show(err);
}
}
}