如何在windows Phone 7/8中读取本地.json文件和显示数据

本文关键字:json 文件 数据 显示 读取 windows Phone | 更新日期: 2023-09-27 18:04:52

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

如何在windows Phone 7/8中读取本地.json文件和显示数据

看起来你正在尝试访问Windows phone上的C://驱动器…这根本不存在。观看此视频:http://channel9.msdn.com/Series/Building-Apps-for-Windows-Phone-8-Jump-Start/Building-Apps-for-Windows-Phone-8-Jump-Start-04-Files-and-Storage-on-Windows-Phone-8