PDA

View Full Version : سوال: مشکل در خواندن فایل json



hercool
جمعه 11 بهمن 1392, 08:53 صبح
سلام دوستان من می خوام از یک فایل json اطلاعات رو بخونم کد ها رو قرار میدم اما این اتفاق نمی افته ممنون میشم راهنماییم کنید
کد کلاس
public class sample
{
public sample() { }
private static ObservableCollection<sample> _sample = new ObservableCollection<sample>();
private ObservableCollection<samplee> _asamplee = new ObservableCollection<samplee>();
public ObservableCollection<samplee> asamplee { get { return this._asamplee; } }
public static async Task LoadLocalData_DataDoctorAsync()
{
// Retrieve recipe data from Recipes.txt
var file = await Package.Current.InstalledLocation.GetFileAsync("sample.txt");
var result = await FileIO.ReadTextAsync(file);

// Parse the JSON recipe data
var recipes = JsonArray.Parse(result);

// Convert the JSON objects into RecipeDataItems and RecipeDataGroups
Createsamplee(recipes);

}

private static samplee Createsamplee(JsonArray array)
{
samplee samplee = new samplee();
foreach (var item in array)
{
var obj = item.GetObject();


foreach (var key in obj.Keys)
{
IJsonValue val;
if (!obj.TryGetValue(key, out val))
continue;
switch (key)
{
case "name": samplee.name = val.GetString();
break;
case "family": samplee.family = val.GetString();
break;

}
}
}
return samplee;


}
public static void writesamplee(sample sample){}
public string start()
{
return "a";
}

}
و
public class samplee:INotifyPropertyChanged
{
public samplee() { }
public string name { get; set; }
public string family { get; set; }


public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
به کمک دو تابع خواستم اطلاعات رو بخونم اما در متغییر مقادیر اماده نمیشه ممنون میشم راهنمایی کنید
public MainPage()
{
this.InitializeComponent();
//getdata();
getdata2();
}

public static async Task getdata()
{
sample s = new sample();
s.start();
await sample.LoadLocalData_DataDoctorAsync();
}
public void getdata2()
{
var data = sample.LoadLocalData_DataDoctorAsync();

}
اینم نمونه مقادیر

[
'Jsample':{'name':'masoud','family':'fallah'},{'na me':'mohsen','family':'fallah'}


]