Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

I'm using the Stack Apps API. Retrieving questions by tags works well, and the JSON is returned. Now I need to parse the JSON and there is something wrong with my code:

$.ajax({
    url: 'http://api.stackexchange.com/2.1/search?page=1&pagesize=15&tagged='+_tags+'&site=stackoverflow',
    dataType:'json',
    type:'GET',
    error:function(e){
      console.log(e);
    },
    beforeSend:function(){
    },
    success: function(data){

      for(var I = 0 ; I < data.length; I ++){
       alert(data.items[I].question_id);
      }
    }
 });

the JSON is not alerted, nothing is alerted.

the JSON I retrieve is like this:

{
    "items":[
        {
            "question_id":13744926,
            "creation_date":1354801586,
            "last_activity_date":1354802622,
            "score":-3,
            "answer_count":3,
            "title":"How to avoid concurrent exception in ArrayList in android?",
            "tags":[ "java", "android"],
            "view_count":33,
            "owner":{
                ...
            },
            "link":"http://stackoverflow.com/questions/13744926/how-to-avoid-concurrent-exception-in-arraylist-in-android",
            "is_answered":true
        },
        ...
        ...
    ],
    "quota_remaining":271,
    "quota_max":300,
    "has_more":true
}

What am I doing wrong?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Thanks to Dave for this ;) Your for loop should be:

var i, l;
for (i = 0, l = data.items.length; i < l; i++) {
    // Get your data here
}
share|improve this answer
    
hey hey you're stoling :D –  Badaboooooom Dec 6 '12 at 20:33
    
Why 'stolling'? I don't get it, sorry ... –  Pierre.Vriens Apr 12 at 18:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .