How to extract only 1 image from Json?

Asked

Viewed 395 times

0

Hello, I need to extract only 1 image of this Json. Here is my angular code to pull the records from the api via get.

    var app = angular.module('myApp', []);
    app.controller('carrosCtrl', function($scope, $http) {
       $http.get("http://www.folhacar.com.br/api/listAnuncios?revenda_id=528&cnpj=13733235000134").success(function(data) { 
        $scope.nomes = data;
      });
    });

The field in this api is "images":["imagem01","imagem02","imagem03"]

  • This is actually an array and not a JSON.

  • 1

    @Danielamarquesdemorais this is actually a JSON with an array inside; because it has an array it is impossible to be an Object

  • @Moshmage Perfect, really. He implied that the "json" element he referred to was only "imagens":["imagem01","imagem02","imagem03"]

2 answers

1


I would say a simple data[N] (where N is a number) will remove the part you need. Either this or data.imagens[N]. But since I don’t know how the server is responding to that query (aka we don’t see the backend code) it’s a bit "wind-wise" that I say this.

You can show us how the backend responds to that answer?

  • Perfect Moshmage, it was just that, I tested it here and it worked. Thank you very much!

0

Browser other questions tagged

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