WinJS使用JSON解析网站

时间:2013-01-17 21:54:10

标签: javascript html winjs

我正在尝试使用JSON解析网站。我一直在JSON.parse行遇到错误。这是我一直在那条线上的错误:

    Exception is about to be caught by JavaScript library code at line 31, column 21 in ms-appx://37099737-8761-481d-b1e3-38412d272486/pages/search1/search1.js

    0x800a03f6 - JavaScript runtime error: Invalid character

    If there is a handler for this exception, the program may be safely continued.     

这是我的代码:

    loadWebsite: function (totalSearch) {
        WinJS.xhr({url: totalSearch}).then(
            function (response) {
                var json = JSON.parse(response.responseText); //this line here
                var list = new WinJS.Binding.List(json.results);
                gridView1.winControl.itemDataSource = list.dataSource;
            },
        function (error){ console.log(error); },
        function (progress) { }
        );
        return;
    }

1 个答案:

答案 0 :(得分:1)

网站通常以HTML格式发送,这看起来与JSON完全不同。

您应该使用HTML解析器来解析HTML,并使用JSON解析器来解析JSON。有道理,没有?