0

我正在尝试使用 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;
    }
4

1 回答 1

1

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

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

于 2013-01-17T22:01:35.003 回答