我尝试了几种不同的方法,还没有运气。注意:在第二个 if 语句中,我输入了长 json 字符串。但是,我不想写长的 json 字符串,而是想从 json 文件中读取。
private void Pivot_LoadingPivotItem_1(object sender, PivotItemEventArgs e)
{
try
{
if(e.Item == item1)
{
list1.Items.Clear();
//string stopslist1 = @"[{""Name"":""Communication Sciences""},{""Name"":""Hope Lodge""},{""Name"":""Juniper-Poplar""}]";
IsolatedStorageFile mysfile = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fs = mysfile.OpenFile(@"c:\users\prime\documents\visual studio 2012\Projects\BullRunnertest3\BullRunnertest3\stopsA.json",FileMode.Open, FileAccess.Read);
using (StreamReader re = new StreamReader(fs))
{
string stopslist1 = re.ReadToEnd();
}
List<RouteStops> stops = JsonConvert.DeserializeObject<List<RouteStops>>(stopslist1);
foreach(RouteStops em in stops)
{
string name = em.Name;
list1.Items.Add(name);
}
}
else if (e.Item == item2)
{
list2.Items.Clear();
string stopslist2 = @"[{""Name"":""Computer Sciences""},{""Name"":""Hope for Lodge""},{""Name"":""Juniper and Poplar""}]";
List<RouteStops> stops = JsonConvert.DeserializeObject<List<RouteStops>>(stopslist2);
foreach (RouteStops em in stops)
{
string name = em.Name;
list2.Items.Add(name);
}
}
else......