3

我尝试了几种不同的方法,还没有运气。注意:在第二个 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......
4

1 回答 1

3

看起来您正试图访问 Windows 手机上的 C:// 驱动器......它不存在。观看此视频:http ://channel9.msdn.com/Series/Building-Apps-for-Windows-Phone-8-Jump-Start/Building-Apps-for-Windows-Phone-8-Jump-Start-04- Windows-Phone-8 上的文件和存储

了解如何从本地存储访问文件。

于 2013-03-20T21:13:37.257 回答