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.

Hi i'm using the stackapps api, retrieving questions by tags the code works well, and the json is returned, now i need to parse the json and i think there is somenthing 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 somenthingl ike 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":{"user_id":1434806,"display_name":"Sandeep Dhull","reputation":14,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/e1caf9a1484cdebcc34527f93bf5881c?d=identicon&r=PG","link":"http://stackoverflow.com/users/1434806/sandeep-dhull","accept_rate":70},"link":"http://stackoverflow.com/questions/13744926/how-to-avoid-concurrent-exception-in-arraylist-in-android","is_answered":true},{"question_id":13745003,"creation_date":1354801881,"last_activity_date":1354802458,"score":0,"answer_count":3,"title":"Why would compiler fail on duplicate class if they belong to different packages?","tags":["java","maven","m2e"],"view_count":18,"owner":{"user_id":1864054,"display_name":"Daniel","reputation":63,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/5bcfcea058ccd413bc302b8362e70971?d=identicon&r=PG","link":"http://stackoverflow.com/users/1864054/daniel"},"link":"http://stackoverflow.com/questions/13745003/why-would-compiler-fail-on-duplicate-class-if-they-belong-to-different-packages","is_answered":true},{"question_id":13744848,"last_edit_date":1354802372,"creation_date":1354801279,"last_activity_date":1354802421,"score":2,"answer_count":3,"title":"How to make x is a whole number a condition in Java","tags":["java"],"view_count":45,"owner":{"user_id":1882499,"display_name":"Adam Milsom","reputation":11,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/acc2dbf0d26f5b1ca6ddd3f9c2bb0806?d=identicon&r=PG","link":"http://stackoverflow.com/users/1882499/adam-milsom"},"link":"http://stackoverflow.com/questions/13744848/how-to-make-x-is-a-whole-number-a-condition-in-java","is_answered":true},{"question_id":13744864,"last_edit_date":1354802219,"creation_date":1354801352,"last_activity_date":1354802219,"score":0,"answer_count":2,"title":"How to initiate using generic type in java","tags":["java","generics"],"view_count":49,"owner":{"user_id":1823740,"display_name":"Dipak","reputation":31,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/738820f8b20c0c3ebd7f49338fb2f6f0?d=identicon&r=PG","link":"http://stackoverflow.com/users/1823740/dipak"},"link":"http://stackoverflow.com/questions/13744864/how-to-initiate-using-generic-type-in-java","is_answered":false},{"question_id":13683126,"creation_date":1354537177,"last_activity_date":1354802208,"score":2,"answer_count":1,"title":"can srcgen4javasssit be used to generate source code of my existing class?","tags":["java","javassist"],"view_count":14,"owner":{"user_id":1872518,"display_name":"adeeliqbal","reputation":11,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/babab7822c70c5d5202c4b6d3418955b?d=identicon&r=PG","link":"http://stackoverflow.com/users/1872518/adeeliqbal"},"link":"http://stackoverflow.com/questions/13683126/can-srcgen4javasssit-be-used-to-generate-source-code-of-my-existing-class","is_answered":true},{"question_id":13744076,"last_edit_date":1354802202,"creation_date":1354798542,"last_activity_date":1354802202,"score":6,"answer_count":0,"title":"More unicode characters in windows console than expected","tags":["java","windows","unicode","console"],"view_count":26,"owner":{"user_id":971355,"display_name":"ka3ak","reputation":211,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/a45d2cf29aa7e12360246fa40ccd6074?d=identicon&r=PG","link":"http://stackoverflow.com/users/971355/ka3ak","accept_rate":90},"link":"http://stackoverflow.com/questions/13744076/more-unicode-characters-in-windows-console-than-expected","is_answered":false},{"question_id":8486725,"last_edit_date":1323799665,"creation_date":1323767730,"last_activity_date":1354802135,"score":0,"answer_count":3,"title":"URI Template variable containing a path?","tags":["java","http","rest","uri","uritemplate"],"view_count":191,"owner":{"user_id":740480,"display_name":"maVVamaldo","reputation":163,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/c65b450288923d980318dae3c54f3f33?d=identicon&r=PG","link":"http://stackoverflow.com/users/740480/mavvamaldo","accept_rate":79},"link":"http://stackoverflow.com/questions/8486725/uri-template-variable-containing-a-path","is_answered":true},{"question_id":13726046,"last_edit_date":1354739264,"creation_date":1354719610,"last_activity_date":1354802008,"score":2,"answer_count":6,"accepted_answer_id":13726091,"title":"Search an ArrayList for a particular Object","tags":["java","class","object","arraylist"],"view_count":54,"owner":{"user_id":1377826,"display_name":"sharon Hwk","reputation":391,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/f0b6e6e3ea80d80ea4f6c4955c10031c?d=identicon&r=PG","link":"http://stackoverflow.com/users/1377826/sharon-hwk","accept_rate":80},"link":"http://stackoverflow.com/questions/13726046/search-an-arraylist-for-a-particular-object","is_answered":true},{"question_id":10949461,"creation_date":1339160835,"last_activity_date":1354801985,"score":3,"answer_count":2,"accepted_answer_id":10950824,"title":"Javafx 2 click and double click","tags":["java","click","javafx","javafx-2","double-click"],"view_count":735,"owner":{"user_id":1247362,"display_name":"Delkaspo","reputation":23,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/c73aeecf4fb9f72156de5895603147c6?d=identicon&r=PG","link":"http://stackoverflow.com/users/1247362/delkaspo"},"link":"http://stackoverflow.com/questions/10949461/javafx-2-click-and-double-click","is_answered":true},{"question_id":13745040,"creation_date":1354801983,"last_activity_date":1354801983,"score":0,"answer_count":0,"title":"The String QUERY_EVALUATIONEXPRESSION is not using the local variable","tags":["java","data-migration"],"view_count":8,"owner":{"user_id":1865053,"display_name":"user1865053","reputation":11,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/12aca36ed0f4bac4e8496fc2564d79f5?d=identicon&r=PG","link":"http://stackoverflow.com/users/1865053/user1865053"},"link":"http://stackoverflow.com/questions/13745040/the-string-query-evaluationexpression-is-not-using-the-local-variable","is_answered":false},{"question_id":13744959,"creation_date":1354801709,"last_activity_date":1354801917,"score":0,"answer_count":0,"title":"XML RPC server (PHP, Drupal) incompatibility with client (Java) on long integers","tags":["java","php","drupal","type-conversion","xml-rpc"],"view_count":9,"owner":{"user_id":677139,"display_name":"Dreen","reputation":933,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/bcfc011a6e71684570b0c110f9db1616?d=identicon&r=PG","link":"http://stackoverflow.com/users/677139/dreen","accept_rate":100},"link":"http://stackoverflow.com/questions/13744959/xml-rpc-server-php-drupal-incompatibility-with-client-java-on-long-integers","is_answered":false},{"question_id":13705973,"last_edit_date":1354634756,"creation_date":1354633942,"last_activity_date":1354801916,"score":6,"answer_count":1,"title":"How to draw the multiple lines with different color and undo,redo the paths in android?","tags":["java","android","bitmap"],"view_count":54,"owner":{"user_id":1761025,"display_name":"Kevin Rameshwaran","reputation":114,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/679953c240dd3e701d7a0e10ce7c4641?d=identicon&r=PG","link":"http://stackoverflow.com/users/1761025/kevin-rameshwaran"},"link":"http://stackoverflow.com/questions/13705973/how-to-draw-the-multiple-lines-with-different-color-and-undo-redo-the-paths-in-a","is_answered":false},{"question_id":13744841,"creation_date":1354801265,"last_activity_date":1354801799,"score":0,"answer_count":1,"title":"Opening JNLP File in Java 6 JRE instead of JRE 7","tags":["java","windows","java-web-start"],"view_count":11,"owner":{"user_id":54522,"display_name":"Dario","reputation":1284,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/7fe8ea996135ab36bb144138b2efd9f0?d=identicon&r=PG","link":"http://stackoverflow.com/users/54522/dario","accept_rate":97},"link":"http://stackoverflow.com/questions/13744841/opening-jnlp-file-in-java-6-jre-instead-of-jre-7","is_answered":false},{"question_id":2898390,"last_edit_date":1274720338,"creation_date":1274717505,"last_activity_date":1354801730,"score":1,"answer_count":5,"accepted_answer_id":2898435,"title":"Java (JSP/Servlet): equivalent of getServletContext() from inside a .jsp","tags":["java","jsp","servlets"],"view_count":1623,"owner":{"user_id":257356,"display_name":"SyntaxT3rr0r","reputation":7925,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/ff30e750ecad4c76dd1fa0c448f15b90?d=identicon&r=PG","link":"http://stackoverflow.com/users/257356/syntaxt3rr0r","accept_rate":60},"link":"http://stackoverflow.com/questions/2898390/java-jsp-servlet-equivalent-of-getservletcontext-from-inside-a-jsp","is_answered":true},{"question_id":13744774,"creation_date":1354800965,"last_activity_date":1354801728,"score":0,"answer_count":2,"title":"JAVA. Create FileOutputStream using URL","tags":["java"],"view_count":19,"owner":{"user_id":921193,"display_name":"MyTitle","reputation":478,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/8cf1385b4d96155cdad54bc99e18b499?d=identicon&r=PG","link":"http://stackoverflow.com/users/921193/mytitle","accept_rate":75},"link":"http://stackoverflow.com/questions/13744774/java-create-fileoutputstream-using-url","is_answered":true}],"quota_remaining":271,"quota_max":300,"has_more":true}

what i'm doing wrong?

share|improve this question

1 Answer 1

up vote 1 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

You must log in to answer this question.

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