Pull API Rest data and display the data on the screen

Asked

Viewed 663 times

1

I can make an ajax for the service and return the data, I can display the first object Product and its properties, but when there is another object inside Productimage that has more than 5 objects inside, I cannot display their data

$.getJSON("http://www.dipes.com.br/web_api/products/9751/", function(data) {

            console.log(data);
            console.log(data.Product.name);

            var output="<ul>";
            for (var i in data.Product.ProductImage) 
            {
                output+="<li>" + data.Product.ProductImage.i.http  + "</li>";
            }
            output+="</ul>";

            $('span').html(output);
        });

1 answer

2


The code is wrong. The correct way to show the array inside the object would be:

output+="<li>" + data.Product.ProductImage[i].http  + "</li>";
  • This is André, I’ve done this before... and the error continued, the error is this: Html5.html:72 Uncaught Syntaxerror: Unexpected token [ In the console it shows that the error is in [. For you to be aware, I put the Dice in hand and still gives error. ex: console.log(data.Product.Productimage. 1.http);

  • console.log(data.Product.Productimage.1.http); will give error, has to be console.log(data.Product.Productimage[1].http); I tested here and gave no error.

  • This is the code I’m using: $. getJSON("http://www.dipes.com.br/web_api/products/9751/", Function(date) { console.log(data); console.log(data.Product.name); console.log(data.Product.Productimage.[1].http); var output="<ul>"; for (var i in data.Product.Productimage) { output+="<li>" + data.Product.Productimage. [i]. http + "</li>"; } output+="</ul>"; $('span'). html(output); }); Error: Unexpected token [

  • You put "." too much. vc put "console.log(data.Product.Productimage.[1].http);" the correct is "console.log(data.Product.Productimage[1].http);" . After Productimage has no point

  • Exactly!!! Stupid mistake, I’m sorry! Thanks for your help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.