|
本帖最后由 flyeblue 于 2013-5-30 03:49 编辑
{"p": {"out": 7, "incoming": 0}, "up": 30.358999967575073, "my_stale_r": {"orphan_stale": null, "stale": null, "dead_stale": null}, "attempts": 48049638107769001, "warnings": [], "block_value": 0.30771641, "dead_hash_rates": {}, "efficiency_if_miner_perfect": null, "shares": {"total": 0, "orphan": 0, "dead": 0}, "efficiency": null, "my_share_counts_in_last_hour": {"doa_stale_shares": 0, "stale_shares": 0, "orphan_stale_shares": 0, "shares": 0, "unstale_shares": 0}, "miner_hash_rates": {"099": 1164894834.2242064}, "last_hour": {"note": "DEPRECATED", "actual": 0, "rewarded": 0.0, "nonstale": 0.0}, "donation_proportion": 0.01, "attempts_to_share": 7448126081565}
上面这段数据,怎么才能在autoit里正确的处理?最好能够读取跟写入
看了大家的帮助,总算有了思路,现在基本实现了基础功能Func _DictKeys($Dict)
;获取字典所有关键字
Local $Keys[1]=[]
Local $tempKeys
$tempKeys=StringRegExp($Dict,'("\w+"):\h*(?:{.*?}|.+?(?=,\h*|}\s*$))',3)
If IsArray($tempKeys) Then
;~ ConsoleWrite('find'&@CRLF)
$Keys=$tempKeys
EndIf
Return $Keys
EndFunc
Func _DictKeysCheck($dict,$CheckKey)
;检测指定的关键字是否存在字典中
Local $Keys
Local $temp
$Keys=_DictKeys($dict)
If IsArray($Keys) Then
For $temp In $Keys
If $CheckKey=$temp Then
Return True
EndIf
Next
EndIf
Return False
EndFunc
Func _DictValue($dict,$DictKey)
;依据字典关键字获取字典值
Local $tempValue,$Value=''
Local $tempValueRegExp=':\h*((?:{.*?}|.+?(?=,\h*|}\s*$)))'
If _DictKeysCheck($dict,$DictKey) Then
$tempValueRegExp=$DictKey&$tempValueRegExp
$tempValue=StringRegExp($dict,$tempValueRegExp,3)
If IsArray($tempValue) Then
;~ ConsoleWrite('find1'&@CRLF)
$Value=$tempValue[0]
EndIf
EndIf
Return $Value
EndFunc
Func _DictValueChang(ByRef $dict,$DictKey,$NewValue)
;改变字典项值,如果关键字不存在则不改变
Local $tempValueRegExp=':\h*((?:{.*?}|.+?(?=,\h*|}\s*$)))'
;~ Local $tempDict
If _DictKeysCheck($dict,$DictKey) Then
$tempValueRegExp=$DictKey&$tempValueRegExp
;~ ConsoleWrite($tempValueRegExp&@CRLF)
;~ ConsoleWrite('find1'&@CRLF)
$dict=StringRegExpReplace($dict,$tempValueRegExp,$DictKey&':'&$NewValue)
;~
;~ Else
;~ $tempDict=$dict
EndIf
;~ Return $tempDict
EndFunc
Func _DictKeyDel(ByRef $dict,$DelKey)
;删除字典项,依据关键字
Local $tempValueRegExp=':\h*((?:{.*?}|.+?(?=,\h*|}\s*$))),'
If _DictKeysCheck($dict,$DelKey) Then
$tempValueRegExp=$DelKey&$tempValueRegExp
$dict=StringRegExpReplace($dict,$tempValueRegExp,'')
EndIf
EndFunc
Func _DictAdd(ByRef $dict,$AddKey,$AddValue)
;添加字典项,如果字典关键字存在则不改变
Local $tempRegExp='(}$)'
Local $tempRegExpNew
If Not _DictKeysCheck($dict,$AddKey) Then
$tempRegExpNew=','&$AddKey&':'&$AddValue&'\1'
$dict=StringRegExpReplace($dict,$tempRegExp,$tempRegExpNew)
EndIf
EndFunc
示例如下:$stringDict='{"p": {"out": 7, "incoming": 0}, "up": 30.358999967575073, "my_stale_r": {"orphan_stale": null, "stale": null, "dead_stale": null}, "attempts": 48049638107769001, "warnings": [], "block_value": 0.30771641, "dead_hash_rates": {}, "efficiency_if_miner_perfect": null, "shares": {"total": 0, "orphan": 0, "dead": 0}, "efficiency": null, "my_share_counts_in_last_hour": {"doa_stale_shares": 0, "stale_shares": 0, "orphan_stale_shares": 0, "shares": 0, "unstale_shares": 0}, "miner_hash_rates": {"099": 1164894834.2242064}, "last_hour": {"note": "DEPRECATED", "actual": 0, "rewarded": 0.0, "nonstale": 0.0}, "donation_proportion": 0.01, "attempts_to_share": 7448126081565}'
;~ $stringDict='{"out": 7, "incoming": 0}
$temp=_DictKeys($stringDict)
If IsArray($temp) Then
For $aa In $temp
ConsoleWrite($aa&@CRLF)
Next
Else
ConsoleWrite('无'&@CRLF)
EndIf
ConsoleWrite('************************'&@CRLF)
ConsoleWrite(_DictKeysCheck($stringDict,'"p"')&@CRLF)
ConsoleWrite(_DictValue($stringDict,'"p"')&@CRLF)
ConsoleWrite('************************'&@CRLF)
ConsoleWrite(_DictKeysCheck($stringDict,'"incoming"')&@CRLF)
ConsoleWrite(_DictValue($stringDict,'"incoming"')&@CRLF)
ConsoleWrite('************************'&@CRLF)
ConsoleWrite(_DictValue($stringDict,'"out"')&@CRLF)
_DictValueChang($stringDict,'"out"','00000')
ConsoleWrite($stringDict&@CRLF)
ConsoleWrite(_DictValue($stringDict,'"out"')&@CRLF)
ConsoleWrite('************************'&@CRLF)
_DictKeyDel($stringDict,'out')
ConsoleWrite($stringDict&@CRLF)
ConsoleWrite(_DictValue($stringDict,'"out"')&@CRLF)
_DictKeyDel($stringDict,'"out"')
ConsoleWrite($stringDict&@CRLF)
ConsoleWrite(_DictValue($stringDict,'"out"')&@CRLF)
ConsoleWrite('************************'&@CRLF)
ConsoleWrite(_DictValue($stringDict,'"up"')&@CRLF)
Local $t[1]=[]
If _DictValue($stringDict,'"up"')='' Then ConsoleWrite('空字符串'&@CRLF)
If _DictValue($stringDict,'"up"')=$t Then ConsoleWrite('空数组'&@CRLF)
_DictAdd($stringDict,'"up"',30.358999967575073)
ConsoleWrite(_DictValue($stringDict,'"up"')&@CRLF)
|
|