traverse JSON objects and identify them

1

I have a JSON that brings me several objects as I could go through them and identify them in order to work with each of them separately or bring any of the elements that make it up. Sincerely, I have always complicated this of working with objects: (

function traer(){
    var b = $.get("https://api.myjson.com/bins/1aujl6",
    function (todo) {
     var a = todo;
        console.log(a);
    }, "json");
}

traer();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
asked by Gabriela 08.06.2018 в 22:57
source

1 answer

2

You can traverse it with jQuery.each() . Here is an example:

function traer(){
    var b = $.get("https://api.myjson.com/bins/1aujl6",
    function (todo) {
     var a = todo.data;
     $.each(a, function(i, obj) {
       console.log(obj.name);
       console.log("Price: " + obj.quotes.USD.price);
     });
        
    }, "json");
}

traer();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
answered by 08.06.2018 / 23:00
source