-2

我有一个返回的查询

 {
  "i-22beb65b": {
    "columns": ["time_stamp","stats_value"],
    "data":[
      [42296,2310],
      [42297,2380],
      [42298,2356],
      [42299,1972],
      [42300,4058],
      [42301,4168],
      [42302,2882],
      [42303,2256],
      [42304,1652],
      [42305,1422],
      [42306,2144],
      [42307,1344],
      [42308,2536],
      [42309,3096],
      [42310,2618],
      [42311,3276]
    ]
  },
  "i-9c8999e5": {
    "columns":["time_stamp","stats_value"],
    "data": [
      [42296,3674],
      [42297,3474],
      [42298,3662],
      [42299,3680],
      [42300,4376],
      [42301,2892],
      [42302,3480],
      [42303,4082],
      [42304,3936],
      [42305,3802],
      [42306,4260],
      [42307,3897],
      [42308,3393],
      [42309,4177],
      [42310,3975],
      [42311,4130]
    ]
  },
  "multi": {
    "columns":["time_stamp","stats_value"],
    "data":[]
  }
}

请,我如何对此结果运行查询以获得类似的结果

"i-22beb65b":[[42296,3674],[42307,3897]]
"i-9c8999e5":[[42305,1422],[42306,2144]]

基本上我想使用这些信息来生成一个 Flot 图,它只接受数组,所以我正在寻找一种方法将上面的内容拆分为使用类似我的示例的东西,这样我就可以轻松地传递给 Flot

4

1 回答 1

1

我不知道我是否理解正确,但如果你只想重新定义你的结果查询,你可以这样做:

data = {"i-22beb65b":{"columns":["time_stamp","stats_value"],"data":[[42296,2310],[42297,2380],[42298,2356],[42299,1972],[42300,4058],[42301,4168],[42302,2882],[42303,2256],[42304,1652],[42305,1422],[42306,2144],[42307,1344],[42308,2536],[42309,3096],[42310,2618],[42311,3276]]},"i-9c8999e5":{"columns":["time_stamp","stats_value"],"data":[[42296,3674],[42297,3474],[42298,3662],[42299,3680],[42300,4376],[42301,2892],[42302,3480],[42303,4082],[42304,3936],[42305,3802],[42306,4260],[42307,3897],[42308,3393],[42309,4177],[42310,3975],[42311,4130]]},"multi":{"columns":["time_stamp","stats_value"],"data":[]}}
data.map{|k,v| {k: v["data"]}}
于 2012-10-27T08:28:57.950 回答