【问题标题】:How to read local .json file and display data in Window Phone 7/8?如何在 Window Phone 7/8 中读取本地 .json 文件并显示数据?
【发布时间】:2013-03-20 03:52:05
【问题描述】:

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

【问题讨论】:

  • 您对语言有任何限制。由于 F# 已经有 json 数据提供程序可供读取。如果您可以将 json 文件转储到它会很好。
  • 不,我只使用 c#,您对此有什么建议吗?谢谢
  • 我想你得到了答案。 :),如果还有什么让我知道。

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


【解决方案1】:

您似乎正在尝试访问 Windows 手机上的 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

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

【讨论】:

    猜你喜欢
    • 2017-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-07
    • 2011-11-07
    • 1970-01-01
    相关资源
    最近更新 更多