马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
这是一串JSON格式字符串!
=====================================================================================
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""}]}"
=====================================================================================
按照这位大神的思路是利用"MSScriptControl.ScriptControl"这个组件来实现
这是组件说明:
https://www.jb51.net/article/53369.htm
单步解析操作:
比如调取"Current_period"":635551,"的数字
期号 = 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
=========成功获取到Current_period的数字:635551
这里有个问题,我们平时遇到的很多JSON格式是有很多数组在里面这个时候我们怎么拆解?
就有了接下来的这一段就是利用Current_period内容(引号后面的) 这个Type数组个数去拆解!
=======================================================
总数 = 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
=======================================================
这一步步去剥离每一层就能轻松解析出我们想要的数组值
这里我利用该命令已经成功解决百度云的OCR识别!
|