Excel 怎样将JSON对象转为字符串

2025-04-22 17:56:37
推荐回答(1个)
回答1:

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