Reputation: 373
I'm trying to parse a website using JSON. I keep getting an error at the JSON.parse line. Here is the error I keep getting at that line:
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.
Here is my code:
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;
}
Upvotes: 0
Views: 966
Reputation: 57713
A website is usually sent as HTML, this looks nothing like JSON.
You should HTML parser to parse HTML, and a JSON parser to parse JSON. Makes sense, no?
Upvotes: 1