【问题标题】:Open json file and deserialize it in Windows Phone 8.1在 Windows Phone 8.1 中打开 json 文件并反序列化它
【发布时间】:2015-05-22 08:19:50
【问题描述】:

我的根文件夹中有一个扩展名为 .json 的文件,名为 CurrencyCodesMap.json ,this 是内容。当我尝试读取它并将其保存为我的 NewtonSoft.JsonParsing 的字符串时,输出告诉我“找不到或打开 PDB 文件”,它甚至没有命中断点。

这是我的阅读方法:

    public List<CodesMap> GetCodesMap()
    {
        List<CodesMap> CodesList = JsonConvert.DeserializeObject<List<CodesMap>>(OpenCurrencyCodesMapFile().Result);

        return CodesList;
    }

    public async Task<string> OpenCurrencyCodesMapFile()
    {
        string str = "";

        String ResourceReference = "ms-appx:///CurrencyCodesMap.json";
        StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(ResourceReference, UriKind.Absolute));
        Stream sr = await file.OpenStreamForReadAsync();
        await FileIO.ReadLinesAsync(file);

        foreach (string s in await FileIO.ReadLinesAsync(file))
        {
            str += s;
        }

        return str;
    }

类型:

public class CodesMap
{
    public string CountryCode { get; set; }
    public string CurrencyCode { get; set; }
}

【问题讨论】:

    标签: .net json windows-phone-8.1 windows-8.1 filereader


    【解决方案1】:

    如果您的 jsonfile 位于外部,请将您的存储文件代码替换为

    StorageFile file =await Package.Current.InstalledLocation.GetFileAsync("CurrencyCodesMap.json");
    

    由于代码GetFileFromApplicationUriAsync已经添加了你文件所在的父地址,你不需要指定ms-appx:/// which was resulting in your uri geting concatenated once again.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-26
      • 2015-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多