Obtain values of a JSON per individual

0

Having this function:

<script>
    function testAjax() {
        $.ajax({
            url: 'https://dev.datos.ua.es/uapi/5QGUfP3UM6j5VXERjKvU/datasets/11/data', type: 'GET',
            dataType: "jsonp",
            success: function (data) {
                $.each(data, function (i, item) {
                    //console.log(data);
                    var misdatos = data[i].bbox;                        
                });
            }
        });
    }
</script> 

And in misdatos , there are several longitudes and latitudes:

"-0.515358212377548,38.3869756882801,-0.514646718387274,38.3874205581019" , "-0.527918228743998,38.3810201755556,-0.526373500350929,38.3822401809516" ,

etc. I want to get the first and the second value of each lsita of 4 elements, which are not an array of 4 elements. I tried with split(',') but it does not work.

{
   "data":[
      {
         "id":"0008",
         "nombre":"FACULTAD DE CIENCIAS I",
         "bbox":"-0.515358212377548,38.3869756882801,-0.514646718387274,38.3874205581019",
         "count_geometrias":2098,
         "plantas":"{P1,P3,P2,PB,PS}"
      },
      {
         "id":"0206",
         "nombre":"CENTRO INCUBADOR DE EMPRESAS",
         "bbox":"-0.527918228743998,38.3810201755556,-0.526373500350929,38.3822401809516",
         "count_geometrias":250,
         "plantas":"{PB}"
      },
      {
         "id":"0028",
         "nombre":"RECTORADO Y SERVICIOS GENERALES",
         "bbox":"-0.512869386775825,38.3843008776237,-0.51118534833184,38.3851009545756",
         "count_geometrias":525,
         "plantas":"{PB,PS,P1}"
      },
      {
         "id":"0026",
         "nombre":"FACULTAD DE CIENCIAS DE LA SALUD",
         "bbox":"-0.51488946186396,38.3835841864622,-0.514392670169672,38.384200566229",
         "count_geometrias":749,
         "plantas":"{PB,P1}"
      }
   ]
}
    
asked by Kora 15.10.2017 в 17:12
source

1 answer

1

You only need to do .split(',') and access the data as if it were an array.

function testAjax() {
    $.ajax({
        url: 'https://dev.datos.ua.es/uapi/5QGUfP3UM6j5VXERjKvU/datasets/11/data', type: 'GET',
        dataType: "jsonp",
        success: function (data) {
            $.each(data, function (i, item) {
                var coordenadas = item.bbox.split(',');
                console.log('Coordenadas ' + i);
                console.log(coordenadas[0], coordenadas[1], coordenadas[2], coordenadas[3]);
            });
        }
    });
}
    
answered by 15.10.2017 в 18:41