vba 进行 json 字符百串解析,通常可以借助于 JavaScript 语言,通过 CreateObjec" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 在 <em>VBA</em> 里面怎么读取 <em>json</em>

在 <em>VBA</em> 里面怎么读取 <em>json</em>

作者:乔山办公网日期:

返回目录:excel表格制作


进空间 找号码

vba 进行 json 字符串解析,通常可以借助于 JavaScript 语言,通过 CreateObject 函数来建立 ScriptControl 的实例,再调用其功能,以下是一个简单代码:

Set sc = CreateObject("ScriptControl")
sc.Language = "javascript"
sc.addcode "function jsonParse(s){ return eval_r('('+s+')')}"'json代码
Set oJson = sc.codeobject.jsonParse(jsontext)

vba读取json文件
http://blog.sina.com.cn/s/blog_9598ad1c0101iosr.html

用正则e79fa5e98193e59b9ee7ad94361表达式解析出XY对,存入数组


Sub test()
    Dim a, ind
    json = "{""status"":0,""result"":[{""x"":106.43574112345,""y"":29.833104733025},{""x"":106.43574842922,""y"":29.833105069157}]}"
    Dim re As Object
    Dim mc As Object, mc2 As Object, m As Object
    Set re = CreateObject("VBSCRIPT.REGEXP")
    With re
        .Pattern = """x"":\d+.\d+,""y"":\d+.\d+"
        .Global = True
        Set mc = .Execute(json)
    End With
    
    If mc.Count > 0 Then
        ReDim a(0 To mc.Count - 1, 0 To 1)
        'ind = 1
        For ind = 0 To mc.Count - 1
            Set m = mc(ind)
            With re
                .Pattern = "\d+.\d+"
                .Global = True
                Set mc2 = .Execute(m.Value)
                a(ind, 0) = mc2(0)
                a(ind, 1) = mc2(1)
            End With
        Next ind
    End If
    
    For ind = 0 To UBound(a, 1)
        Debug.Print a(ind, 0), a(ind, 1)
    Next ind
End Sub

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网