Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Problem parsing JSON array from an API.

I have been trying hard to parse this array, but without any success. I am trying to parse an JSON array which sent as result to call to envato API. Here is the code:

function loadPosts()
{
   var data = [];
   var xhr = Ti.Network.createHTTPClient();
   xhr.open("GET", "http://marketplace.envato.com/api/v2/blog-posts:activeden.json");
   xhr.onload = function ()
   {
      var posts = JSON.parse(this.responseText);
      Ti.API.info(posts);
   };

   xhr.send();
}

loadPosts();

Here is the response from the HTTP client:

http://pastie.org/1209705.txt

If someone could tell me how to loop through all the items in the array and get the "title" it would be really helpful.
Thanks in advance.

— asked October 9th 2010 by Axit Patel
  • client
  • http
  • iphone
  • json
  • mobile
  • parsing
  • titanium
0 Comments

2 Answers

  • Loop blog-posts.

    for(i=0;i<blog-posts.length;i++)
    {
       trace("Posted at: " + blog-posts[i].posted_at);
    }
    

    etc..

    — answered October 9th 2010 by Critter
    permalink
    0 Comments
  • Actually you should probably be looping through posts.blog-posts , since you assign the parsed values to post

    — answered October 9th 2010 by Ben Hornedo
    permalink
    1 Comment
    • aye. I had only looked at the json output..

      — commented October 9th 2010 by Critter
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.