0

I'm working on a web-app in Node.JS.

In order to parse a dynamic JSON variable I have followed This Question

However I'm new to JSON and I have a particular JSON response coming from a Server. Here's a piece of JSON response

[{"results":[{"name":"AIENR","tags":{"ch":["922"],"mq":["EMPTY","REAL"],"vs":
["VALID"]},"values":[[1352934000000,145258],[1352934900000,145258],
[1352935800000,145259],[....]

The problem: I want to access to fields inside "values", so in my html page I've done this:

<p>Values: </p>  
<%for (var nodeIndex in queries[0].results[0].values) {%>
        <p><%= queries[0].results[0].values[nodeIndex] %></p>
    <%}%>

and the output (that is correct) is:

Values:

1352934000000,145258

1352934900000,145258

1352935800000,145259

1352936700000,145259

... , ...

Anyway, due to fact that the first value is a timestamp and the second value is a particular measure, I want to store them separately and maybe in the next days use those values to make a chart.

So my question is: How can I split those two values?

Best Wishes.

Community
  • 1
  • 1
alessandrob
  • 1,605
  • 4
  • 20
  • 23
  • 1
    possible duplicate of [Access / process (nested) objects, arrays or JSON](http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – Felix Kling Dec 03 '13 at 00:15
  • 1
    `.values[nodeIndex]` is an array. You can access the first element with `.values[nodeIndex][0]` and second one with `.values[nodeIndex][1]`. – Felix Kling Dec 03 '13 at 00:15
  • Thanks! It solved! it was really simple. I was stuck on the value[i].anotherValue[0] approach, forgetting that's was an array. Hope will be useful to someone else :) – alessandrob Dec 03 '13 at 00:24
  • I made it an answer so that you can mark the question as resolved. – Felix Kling Dec 03 '13 at 01:14

1 Answers1

1

.values[nodeIndex] is an array. You can access the first element with .values[nodeIndex][0] and second one with .values[nodeIndex][1].

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143