Pass Json fix to fix

0

I have this json

var response=[{"ts":"2017-01-01T00:00:00+01:00","v":428},{"ts":"2017-01-02T00:00:00+01:00","v":920}]

and I need to pass it to:

["2017-01-01T00:00:00+01:00,428","2017-01-02T00:00:00+01:00,920"]

better said take it out of json for an array.

Could you help me please

    
asked by 26.05.2017 в 21:07
source

1 answer

0

Here is the code:

// Array para convertir el json
var consumo = [];
// Tu Json
var response = [
  {
    "ts": "2017-01-01T00:00:00+01:00",
    "v": 428
  },
  {
    "ts": "2017-01-02T00:00:00+01:00",
    "v": 920
  }
];

// Iterar el JSON, desde 0 a su tamaño
for(var i = 0; i < response.length; i++){
  // Se arma la estructura que necesitas 
  var item = response[i]["ts"] + ',' + response[i]["v"];
  // Se inserta el item en el el arreglo de salida
  consumo.push(item);
}

console.log(consumo);
    
answered by 26.05.2017 / 21:08
source