Te doy la bienvenida a nuestro sitio web, en este lugar vas a encontrar la solucíon de lo que estabas buscando.
Ejemplo: excel vba json parser
'-----------------------------------------------------------------------------------' VBA JSON Parser'-----------------------------------------------------------------------------------Option Explicit
Private p&, token, dic
Function ParseJSON(json$,Optional key$="obj")AsObject
p =1
token = Tokenize(json)Set dic = CreateObject("Scripting.Dictionary")If token(p)=""Then ParseObj key Else ParseArr key
Set ParseJSON = dic
EndFunctionFunction ParseObj(key$)Do: p = p +1SelectCase token(p)Case"]"Case"[": ParseArr key
Case""If token(p +1)=""Then
p = p +1
dic.Add key,"null"Else
ParseObj key
EndIfCase"": key = ReducePath(key):ExitDoCase":": key = key &"."& token(p -1)Case",": key = ReducePath(key)CaseElse:If token(p +1)<>":"Then dic.Add key, token(p)EndSelectLoopEndFunctionFunction ParseArr(key$)Dim e&Do: p = p +1SelectCase token(p)Case"}"Case"{": ParseObj key & ArrayID(e)Case"[": ParseArr key
Case"]":ExitDoCase":": key = key & ArrayID(e)Case",": e = e +1CaseElse: dic.Add key & ArrayID(e), token(p)EndSelectLoopEndFunction'-----------------------------------------------------------------------------------' Support Functions'-----------------------------------------------------------------------------------Function Tokenize(s$)Const Pattern ="""(([^""\]|\.)*)""|[+-]?(?:0|[1-9]d*)(?:.d*)?(?:[eE][+-]?d+)?|w+|[^s""']+?"
Tokenize = RExtract(s, Pattern,True)EndFunctionFunction RExtract(s$, Pattern,Optional bGroup1Bias AsBoolean,Optional bGlobal AsBoolean=True)Dim c&, m, n, v
With CreateObject("vbscript.regexp").Global= bGlobal
.MultiLine =False.IgnoreCase =True.Pattern = Pattern
If.TEST(s)ThenSet m =.Execute(s)ReDim v(1To m.Count)ForEach n In m
c = c +1
v(c)= n.value
If bGroup1Bias ThenIf Len(n.submatches(0))Or n.value =""""""Then v(c)= n.submatches(0)NextEndIfEndWith
RExtract = v
EndFunctionFunction ArrayID$(e)
ArrayID ="("& e &")"EndFunctionFunction ReducePath$(key$)If InStr(key,".")Then ReducePath = Left(key, InStrRev(key,".")-1)EndFunction
Te invitamos a añadir valor a nuestro contenido informacional dando tu experiencia en las explicaciones.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)