求会正则的大神,我看起来头疼。。。
本帖最后由 devineresse 于 2015-2-15 09:45 编辑_ntes_quote_callback({"1000002":{"code": "1000002", "percent": 0.023256, "high": 13.01, "askvol3": 100600, "askvol2": 76860, "askvol5": 226673, "askvol4": 60700, "price": 12.76, "open": 12.54, "bid5": 12.71, "bid4": 12.72, "bid3": 12.73, "bid2": 12.74, "bid1": 12.75, "low": 12.33, "updown": 0.29, "type": "SZ", "bidvol1": 227400, "status": 0, "bidvol3": 111400, "bidvol2": 11500, "symbol": "000002", "update": "2015/02/13 15:36:42", "bidvol5": 350000, "bidvol4": 613000, "volume": 196804327, "askvol1": 70201, "ask5": 12.8, "ask4": 12.79, "ask1": 12.76, "name": "\u4e07\u79d1\uff21", "ask3": 12.78, "ask2": 12.77, "arrow": "\u2191", "time": "2015/02/13 15:36:36", "yestclose": 12.47, "turnover": 2503342411.83} });
上面是一段股票接口回测代码,现在需要把中括号里面的弄成2列n行的数组。上面的逗号是分对的,冒号是对应的一对。如:array=["code","1000002"]……
#include <Array.au3>
$txt = '_ntes_quote_callback({"1000002":{"code": "1000002", "percent": 0.023256, "high": 13.01, "askvol3": 100600, "askvol2": 76860, "askvol5": 226673, "askvol4": 60700, "price": 12.76, "open": 12.54, "bid5": 12.71, "bid4": 12.72, "bid3": 12.73, "bid2": 12.74, "bid1": 12.75, "low": 12.33, "updown": 0.29, "type": "SZ", "bidvol1": 227400, "status": 0, "bidvol3": 111400, "bidvol2": 11500, "symbol": "000002", "update": "2015/02/13 15:36:42", "bidvol5": 350000, "bidvol4": 613000, "volume": 196804327, "askvol1": 70201, "ask5": 12.8, "ask4": 12.79, "ask1": 12.76, "name": "\u4e07??\u79d1\uff21", "ask3": 12.78, "ask2": 12.77, "arrow": "\u2191", "time": "2015/02/13 15:36:36", "yestclose": 12.47, "turnover": 2503342411.83} });'
$a = StringRegExp($txt, "(?<={)[^{]*?(?=})", 3)
$b = StringSplit($a, ",")
Dim $c[$b]
For $i = 1 To $b
$d = StringSplit($b[$i], ":")
$c[$i-1] = $d
$c[$i-1] = $d
Next
_ArrayDisplay($c)
谢谢完美。
页:
[1]