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.
2 Answers
-
Loop blog-posts.
for(i=0;i<blog-posts.length;i++) { trace("Posted at: " + blog-posts[i].posted_at); }
etc..
-
Actually you should probably be looping through
posts.blog-posts
, since you assign the parsed values topost