I am calling the Flickr data feed in WinJS for a Windows 8 Metro App. When I attempt to parse the feed response with JSON.parse, I get an Invalid Character error. Here is my code:
function processPhotos(result)
{
var photoData = JSON.parse(result.responseText);
//bind here
data.items.forEach(function (item) {
list.push(item);
});
}
function processError(error) {
console.log(error.message);
}
WinJS.xhr({ url: ".gne?format=json" }).then(processPhotos, processError);
WinJS.Namespace.define("data", {
items: groupedItems,
groups: groupedItems.groups,
getItemsFromGroup: getItemsFromGroup
});
Result.ResponseText has the expected content.
Does anyone else encounter this?
I am calling the Flickr data feed in WinJS for a Windows 8 Metro App. When I attempt to parse the feed response with JSON.parse, I get an Invalid Character error. Here is my code:
function processPhotos(result)
{
var photoData = JSON.parse(result.responseText);
//bind here
data.items.forEach(function (item) {
list.push(item);
});
}
function processError(error) {
console.log(error.message);
}
WinJS.xhr({ url: "http://api.flickr./services/feeds/photos_public.gne?format=json" }).then(processPhotos, processError);
WinJS.Namespace.define("data", {
items: groupedItems,
groups: groupedItems.groups,
getItemsFromGroup: getItemsFromGroup
});
Result.ResponseText has the expected content.
Does anyone else encounter this?
Share Improve this question asked Mar 13, 2012 at 4:27 Bill SempfBill Sempf 9762 gold badges14 silver badges40 bronze badges2 Answers
Reset to default 4I had to do this to clear out some of the invalid characters in the responseText. (suggested to me by https://stackoverflow./users/200698/devhammer)
var cleansed = result.responseText.replace(/\\'/g, "'");
var photoData = JSON.parse(cleansed).d;
If you look at the data, you will notice it's not JSON, it's JSONP. That's the reason why JSON.parse()
can't process it. If you want normal JSON, according to the documentation, you should use nojsoncallback=1
:
http://api.flickr./services/feeds/photos_public.gne?format=json&nojsoncallback=1
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745371294a4624806.html
评论列表(0条)