I’m trying to use a framework called appcelerator titanium to make a simple iphone app. I’m trying to bring in an XML source and simply test its length, but nothing is being returned (and no errors are being thrown). I can’t figure out what’s going on. If I swap this XML URL out:
for, say, this one:
http://api.twitter.com/1/statuses/user_timeline.json?screen_name=Superfad
I can find the length just fine, so I’m guessing it’s either some sort of crossdomain issue, or malformed XML, or something. Here’s my code:
var loader = Titanium.Network.createHTTPClient();
// Sets the HTTP request method, and the URL to get data from
//loader.open("GET","http://superfad.com/json/featured");
//loader.open("GET","http://api.twitter.com/1/statuses/user_timeline.json?screen_name=Superfad");
loader.open("GET","http://superfad.com/work/rss");
//loader.open("GET","test.xml");
// Runs the function when the data is ready for us to process
loader.onload = function()
{
Ti.API.log('projects!'); //THIS WORKS
var projects = eval('('+this.responseText+')');
Ti.API.debug('length' + projects.length) //THIS DOES NOT
};
Any ideas what’s wrong?
you are trying to evaluate the xml of the rss feed as json. Your first link returns xml, your second links returns json.
evalwill work on json but not xml. As a note, don’t useevalto parse json. useJSON.parse.