需要解析复杂的Json [英] Need to parse complex Json

查看:173
本文介绍了需要解析复杂的Json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务器获取json数据,试图解析JavaScript中的json,因为它不是直接的json.这是示例

I have and json data getting from an server,struggling to parse json in JavaScript as its not an straight forward json. Here is the sample

[
   {
      "target":"collectd.matrix.oracle.avg_resp_time",
      "datapoints":[
         [8.0, 1365158480],
         [null, 1365158490],
         [null, 1365158500],
         [null, 1365158510],
         [null, 1365158520],
         [null, 1365158530],
         [8.0, 1365158540],
         [null, 1365158550],
         [null, 1365158560],
         [null, 1365158570],
         [null, 1365158580],
         [null, 1365158590],
         [8.0, 1365158600],
         [null, 1365158610],
         [null, 1365158620],
         [null, 1365158630],
         [null, 1365158640],
         [null, 1365158650],
         [8.0, 1365158660],
         [null, 1365158670],
         [null, 1365158680],
         [null, 1365158690],
         [null, 1365158700],
         [null, 1365158710],
         [null, 1365158720],
         [null, 1365158730],
         [null, 1365158740],
         [null, 1365158750],
         [null, 1365158760],
         [null, 1365158770]
      ]
   }
]

在这里,我还需要捕获每个字段的值,例如eg:X=8.0,Y=1365158540

Here i also need to capture value of each field like eg:X=8.0,Y=1365158540

需要一些帮助或逻辑来对此进行解析.

Need some help or logic to parse this.

谢谢, 苏珊

推荐答案

var jsonData = JSON.parse(data)

其中

data = '[{"target": "collectd.matrix.oracle.avg_resp_time", "datapoints": [[8.0, 1365158480], [null, 1365158490], [null, 1365158500], [null, 1365158510], [null, 1365158520], [null, 1365158530], [8.0, 1365158540], [null, 1365158550], [null, 1365158560], [null, 1365158570], [null, 1365158580], [null, 1365158590], [8.0, 1365158600], [null, 1365158610], [null, 1365158620], [null, 1365158630], [null, 1365158640], [null, 1365158650], [8.0, 1365158660], [null, 1365158670], [null, 1365158680], [null, 1365158690], [null, 1365158700], [null, 1365158710], [null, 1365158720], [null, 1365158730], [null, 1365158740], [null, 1365158750], [null, 1365158760], [null, 1365158770]]}]';

jsonData[0]['datapoints']是所有数据点的数组

JSON.parse的参考

这篇关于需要解析复杂的Json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆