按键精灵取html,PC按键精灵 JSON解析
PC按键精灵 JSON解析
发布: 2017-08-21 20:29:24 | 作者: | 来源: 按键精灵资源站
得到如下json,用文本处理很是棘手,怎么办?
[code]{"Current_period":635551,"Lottery_time":"2017-08-21 20:13:24","Type":[{"money":"2","Ranking":9,"Number":"1,3,4,5,6,7,8,9,10"},{"money":"2","Ranking":5,"Number":"1,2,3,5,6,7,8,9,10"},{"money":"2","Ranking":4,"Number":"1,2,3,4,5,7,8,9,10"},{"money":"2","Ranking":3,"Number":"1,2,3,4,5,6,7,9,10"},{"money":"2","Ranking":6,"Number":"1,2,3,4,5,6,7,8,9"}]}[/code]
这个字符串本身有双引号在按键里面,需要用两个来表示一个。
[code]str = "{""Current_period"":635551,""Lottery_time"":""2017-08-21 20:13:24"",""Type"":[{""money"":""2"",""Ranking"":9,""Number"":""1,3,4,5,6,7,8,9,10""},{""money"":""2"",""Ranking"":5,""Number"":""1,2,3,5,6,7,8,9,10""},{""money"":""2"",""Ranking"":4,""Number"":""1,2,3,4,5,7,8,9,10""},{""money"":""2"",""Ranking"":3,""Number"":""1,2,3,4,5,6,7,9,10""},{""money"":""2"",""Ranking"":6,""Number"":""1,2,3,4,5,6,7,8,9""}]}"
[/code]
人都看不懂,我们找个地方格式化一下,太难看了这个。访问这个json格式化网站json格式化
[attachimg]233494[/attachimg]
好了,重点来了,我现在想获取Current_period 对应的数字怎么弄呢?看代码
[code]期号 = json解析(str, "Current_period")
TracePrint 期号
Function json解析(str,json路径)
Set sc = CreateObject("MSScriptControl.ScriptControl")
sc.Language = "JScript"
sc.AddCode "var tmp = " & str & ";"
json解析 = sc.Eval("tmp." & json路径)
End Function[/code] 这样就可以得到Current_period所表示的内容(引号后面的) 问题来了,这个Type里面是一个数组对象,该怎么获取呢?请看代码实现
[code]总数 = json解析(str, "Type.length")'这个后面.length表示这个数组的大小
For i = 0 To 总数 - 1
TracePrint "_____________________________________"
TracePrint json解析(str, "Type[" & i & "].money")
TracePrint json解析(str, "Type[" & i & "].Ranking")
TracePrint json解析(str, "Type[" & i & "].Number")
Next
Function json解析(str,json路径)
Set sc = CreateObject("MSScriptControl.ScriptControl")
sc.Language = "JScript"
sc.AddCode "var tmp = " & str & ";"
json解析 = sc.Eval("tmp." & json路径)
End Function[/code]
好了,今天讲解就到这里,有问题的小白,或者吐槽的大牛欢迎来群搞基:群号174972351
更多推荐
所有评论(0)