简体   繁体   中英

parsing through JSON data with jquery

not too experienced with JSON so i'm hoping you can help. I'm using https://www.zipcodeapi.com/ to try to determine zipcodes within a radius. I can't seem to show the response here but attached is what my console log is showing. I'm trying to grab the zip code and store it in an array but i'm not having any luck doing it. When i tried a test JSON site everything did seem to work fine. Here's the code i'm using:

                }).done(function(data){

        console.log(data); <-- prints what you see in the attached inspector pic
        //reset previous lookup
        zip_codes = [];

        $.each(data, function(index,e){
          zip_codes.push(e.zip_code); <-- does nothing
        });
      });

检查截图

Any and all help is greatly appreciated. Thank you!

The data variable here is an object and not an array. Here array is data.zip_codes , so you should be doing

    $.each(data.zip_codes, function(index,e){
       zip_codes.push(e.zip_code); // will do this time :)
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM