Add.xaml ファイルがあり、レシピ オブジェクトを breakfastRecipe という名前のリストに格納するレシピ クラスがあります。
次に、beakfastRecipe リストを breakfast.json ファイルに保存します。(ここで別のメンバーから見つけた Deserialize/serialize メソッドを使用)
名前と成分を書き込むテキストボックスがいくつかあり、jsonシリアライザーをアクティブにする保存ボタンを使用します。テストメソッドを使用して、すべてが機能しているかどうかをデシリアライザーでテストしました。add.xaml ページで、オブジェクト リストの保存と読み込みが完全に機能しています。
別のページの breakfastList.xaml があり、そこで longlistselector を使用してページにすべてのレシピを入力します。問題は、他のページで作成された breakfast.json ファイルにアクセスする方法がわからないことです。
同じ get/deserializer を使用してデータをロードしました
public async void btnGet_Tap()
{
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
try
{
// Getting JSON from file if it exists, or file not found exception if it does not
StorageFile textFile = await localFolder.GetFileAsync("breakfastList.json");
using (IRandomAccessStream textStream = await textFile.OpenReadAsync())
{
// Read text stream
using (DataReader textReader = new DataReader(textStream))
{
//get size
uint textLength = (uint)textStream.Size;
await textReader.LoadAsync(textLength);
// read it
string jsonContents = textReader.ReadString(textLength);
// deserialize back to our products!
//I only had to change this following line in this function
breakfastRecipe = JsonConvert.DeserializeObject<IList<Recipe>>(jsonContents) as List<Recipe>;
// and show it
//displayProduct();
}
}
}
catch (Exception ex)
{
tester.Text = "error";
}
}
コンストラクタで書くと
朝食レシピ = 新しいリスト(); btnGet_Tap();
私の考えでは、新しいリストを作成していて、btnGet が add.xaml が作成した .json ファイルからデータをロードしますが、機能していません...
私の質問は、最初のページで作成された.jsonファイルに保存されている「2番目のページ」のデータにアクセスする方法です