小编Rui*_*nho的帖子

解析Json Windows8

我已经尝试了多种方法来解析Windows 8中的json并且我很多时候得到了这个错误.

"WinRT信息:WEB_E_INVALID_JSON_STRING"

它得到了一个点,我使用相同的json字符串,如果我从网上读取它,它可以(或多或少)工作,但如果我从本地文件中读取它将无法工作.

下面是代码从网上读取它:

 public async void ExamineJson()
    {
        string responseText = await GetjsonStream();
        ParseJson(responseText);
    }


public async Task<string> GetjsonStream()
    {
        HttpClient client = new HttpClient();
        string url = "http://rmarinho.facilit.us/app/d/rtp/config.json";
        HttpResponseMessage response = await client.GetAsync(url);
        return response.Content.ReadAsString();
    }



    private static void ParseJson(string responseText)
    {
        JsonObject root = new JsonObject(responseText);
        string epg = root.GetNamedString("epgurl");

        JsonArray themes = root["themes"].GetArray();

        for (int i = 0; i < themes.Count; i++)
        {

            JsonObject section = themes[i].GetObject();

        }

    }
Run Code Online (Sandbox Code Playgroud)

所以这可行,但是如果我使用相同的解析方法并使用此代码从我的应用程序中的本地文件获取文件,如果失败并显示错误"WinRT信息:WEB_E_INVALID_JSON_STRING".

FileSync.Read<string>(installedLocation, "config.json",
           (fileSize, reader) => …
Run Code Online (Sandbox Code Playgroud)

c# json microsoft-metro windows-8

6
推荐指数
1
解决办法
4735
查看次数

标签 统计

c# ×1

json ×1

microsoft-metro ×1

windows-8 ×1