1

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?

1 Answer 1

2

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
}
2
  • hey hey you're stoling :D Commented Dec 6, 2012 at 20:33
  • Why 'stolling'? I don't get it, sorry ... Commented Apr 12, 2015 at 18:24

You must log in to answer this question.

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