-3

I am trying to read data which I have received from a JSON object in the following format:

  var series = [{"Data":{"ArrayData":null,"DoubleArrayData":["\/Date(1481846400090)\/",1,"\/Date(1481846400100)\/",1,"\/Date(1481846400110)\/",1,"\/Date(1481846400120)\/",1],"Points":null,"SeriesData":null}, {"Data": ... }, {"Data": ... }];

I have tried doing the following in order to read the Data in the "DoubleArrayData" field:

 var ns = series[0].Data[1].DoubleArrayData[0];

However it returns undifined. What am I doing wrong?

Diogo Martinho
  • 137
  • 2
  • 7

5 Answers5

2

Data is not an array, so you should access it's properties directly series[0].Data.DoubleArrayData[0]

var series = [{
  "Data": {
    "ArrayData": null,
    "DoubleArrayData": ["\/Date(1481846400090)\/", 1, "\/Date(1481846400100)\/", 1, "\/Date(1481846400110)\/", 1, "\/Date(1481846400120)\/", 1],
    "Points": null,
    "SeriesData": null
  }
}];

console.log(series[0].Data.DoubleArrayData[0]);
Nope
  • 22,147
  • 7
  • 47
  • 72
1

No need to add [0] to Data as it is an Object property, not an array:

series[0].Data.DoubleArrayData[0]
// Returns "/Date(1481846400090)/"
Antony
  • 1,253
  • 11
  • 19
1

Data is not an array, you don't have to use [1] (it should be used on array to get the index):

var ns = series[0].Data.DoubleArrayData[0];
Mistalis
  • 17,793
  • 13
  • 73
  • 97
0

In your json object , Data is Object not an Array

var ns = series[0].Data.DoubleArrayData[0]
Vladu Ionut
  • 8,075
  • 1
  • 19
  • 30
0

You are not accessing the json object correctly.

Your example json object:

var series = [{"Data":{"ArrayData":null,"DoubleArrayData":["\/Date(1481846400090)\/",1,"\/Date(1481846400100)\/",1,"\/Date(1481846400110)\/",1,"\/Date(1481846400120)\/",1],"Points":null,"SeriesData":null}}];

To access "DoubleArrayData field

var ns = series[0]['Data']['DoubleArrayData']
Vaibhav Kumar
  • 544
  • 5
  • 17