结构中的数组

时间:2012-10-27 08:19:57

标签: ruby json coldfusion

我有一个返回

的查询
 {
  "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

1 个答案:

答案 0 :(得分: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"]}}