c# - Window Phone 7/8如何读取本地.json文件并显示数据?

标签 c# json windows-phone-8 json.net windows-phone

我尝试了几种不同的方法,但还没有成功。注意:在第二个 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 上的 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

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

关于c# - Window Phone 7/8如何读取本地.json文件并显示数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15514968/

相关文章:

c# - 检查空格 Regex C#

c# - Java 相当于使用别名的 C#

java - 如何将 3h 解析为 java?(无法设置以数字开头的变量)

java - 使用 Jackson 将 Spring 3 ArrayList 序列化为 JSON 而无需包装到对象(无名称)

windows-phone-7 - 闪屏中的视频

c# - 公共(public) API 的正确命名空间

c# - 为什么检索匿名类型的属性名称会产生以下结果?

java - 如何在 Java 中转换以数字作为字段键的 json 对象?

windows-phone-8 - 从 WP8 应用分享链接

c# - 深度复制一个值类型的锯齿状数组而不进行序列化