简体   繁体   English

JavaScript-解析动态json

[英]JavaScript - Parsing a dynamic json

I'm working on a web-app in Node.JS. 我正在使用Node.JS开发一个Web应用程序。

In order to parse a dynamic JSON variable I have followed This Question 为了解析动态JSON变量,我遵循了这个问题

However I'm new to JSON and I have a particular JSON response coming from a Server. 但是,我是JSON的新手,但是我有一个来自服务器的特定JSON响应。 Here's a piece of JSON response 这是一块JSON响应

[{"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: 问题:我想访问"values"内的字段,因此在html页面中,我这样做:

<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. 最好的祝愿。

.values[nodeIndex] is an array. .values[nodeIndex]是一个数组。 You can access the first element with .values[nodeIndex][0] and second one with .values[nodeIndex][1] . 您可以使用.values[nodeIndex][0]访问第一个元素,而使用.values[nodeIndex][1]访问第二个元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM