ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¦p¦ó¶×¤J¤j¶qªº¸ê®Æ¶i¤J¸ê®Æ®w

[µo°Ý] ¦p¦ó¶×¤J¤j¶qªº¸ê®Æ¶i¤J¸ê®Æ®w

¦U¦ì«e½ú¥­¦w
½Ð°Ý§ó´«·sºô¯¸ , ©Ò¦³ªº¸ê®Æ³£­n¥Î¤H¤uÁä¤J¶Ü ?
¤@¤j°ï¸ê®Æ¤@µ§¤@µ§ªº¶K , ¯u¬O¶Ì²´
¦³¤èªk¥i¥H¾ã§å¶×¤J¶Ü ?
µL¤îºÉªº§V¤O¤W¶i

¦U¦ì«e½ú¥­¦w
½Ð°Ý§ó´«·sºô¯¸ , ©Ò¦³ªº¸ê®Æ³£­n¥Î¤H¤uÁä¤J¶Ü ?
¤@¤j°ï¸ê®Æ¤@µ§¤@µ§ªº¶K , ¯u¬O¶Ì²´
¦³¤è ...
vinejason µoªí©ó 2018-4-10 11:23


¦³¨S¦³¥i¥H°µ¨ì
excel§ó·s¸ê®Æ
ºô¯¸¤Wªº¸ê®Æ¤]¦P¨B§ó·s
µL¤îºÉªº§V¤O¤W¶i

TOP

­n¥ÎEXCEL °µ ¦n§xÃø ªº
­n¦³ºô­¶ªº°ò¦ª¾ÃÑ  ÁÙ­n «á¥xªºª¾ÃÑ ¤ñ¦pJSP.PHP¨ºÃþ   ¦Ó¦n¦h®É ³£¬O¤£¯à¿é¤Jªº¦h  ¦]¬°¤j¦hºô¯¸ªº¦w¥þ©Ê°ÝÃD  

¥i¦æ©Ê¤£°ª   ¦Ó¥B¤£¹ê»Ú   ¤Ó³Â·Ð

ºô¤W¨Ò¤l :

ªþ录¤@¡GVBA处²zJSONªº类¼Ò块

Option Explicit
'================================
' VBA处²zJSON¤å¥óªº类¼Ò块
'
' http://www.cnhup.com
'================================
Const INVALID_JSON      As Long = 1
Const INVALID_OBJECT    As Long = 2
Const INVALID_ARRAY     As Long = 3
Const INVALID_BOOLEAN   As Long = 4
Const INVALID_NULL      As Long = 5
Const INVALID_KEY       As Long = 6

Private Sub Class_Initialize()

End Sub

Private Sub Class_Terminate()

End Sub

Public Function parse(ByRef str As String) As Object

    Dim index As Long
    index = 1
   
    On Error Resume Next

    Call skipChar(str, index)
    Select Case Mid(str, index, 1)
    Case "{"
        Set parse = parseObject(str, index)
    Case "["
        Set parse = parseArray(str, index)
    End Select

End Function

Private Function parseObject(ByRef str As String, ByRef index As Long) As Object

    Set parseObject = CreateObject("Scripting.Dictionary")
   
    ' "{"
    Call skipChar(str, index)
    If Mid(str, index, 1) <> "{" Then Err.Raise vbObjectError + INVALID_OBJECT, Description:="char " & index & " : " & Mid(str, index)
    index = index + 1
   
    Do
   
        Call skipChar(str, index)
        If "}" = Mid(str, index, 1) Then
            index = index + 1
            Exit Do
        ElseIf "," = Mid(str, index, 1) Then
            index = index + 1
            Call skipChar(str, index)
        End If
        
        Dim key As String
        
        ' add key/value pair
        parseObject.Add key:=parseKey(str, index), Item:=parseValue(str, index)
        
    Loop

End Function

Private Function parseArray(ByRef str As String, ByRef index As Long) As Collection

    Set parseArray = New Collection
   
    ' "["
    Call skipChar(str, index)
    If Mid(str, index, 1) <> "[" Then Err.Raise vbObjectError + INVALID_ARRAY, Description:="char " & index & " : " + Mid(str, index)
    index = index + 1
   
    Do
        
        Call skipChar(str, index)
        If "]" = Mid(str, index, 1) Then
            index = index + 1
            Exit Do
        ElseIf "," = Mid(str, index, 1) Then
            index = index + 1
            Call skipChar(str, index)
        End If
        
        ' add value
        parseArray.Add parseValue(str, index)
        
    Loop

End Function

Private Function parseValue(ByRef str As String, ByRef index As Long)

    Call skipChar(str, index)
   
    Select Case Mid(str, index, 1)
    Case "{"
        Set parseValue = parseObject(str, index)
    Case "["
        Set parseValue = parseArray(str, index)
    Case """", "'"
        parseValue = parseString(str, index)
    Case "t", "f"
        parseValue = parseBoolean(str, index)
    Case "n"
        parseValue = parseNull(str, index)
    Case Else
        parseValue = parseNumber(str, index)
    End Select

End Function

TOP

        ÀR«ä¦Û¦b : «H¤ß¡B¼Ý¤O¡B«i®ð¤TªÌ¨ã³Æ¡A«h¤Ñ¤U¨S¦³°µ¤£¦¨ªº¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD