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.

4
  • 1
    possible duplicate of Access / process (nested) objects, arrays or JSON Commented Dec 3, 2013 at 0:15
  • 1
    .values[nodeIndex] is an array. You can access the first element with .values[nodeIndex][0] and second one with .values[nodeIndex][1]. Commented Dec 3, 2013 at 0: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 :) Commented Dec 3, 2013 at 0:24
  • I made it an answer so that you can mark the question as resolved. Commented Dec 3, 2013 at 1:14

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.