JSON with VBA
■コード
' Microsoft Script Control 1.0
' JSON 処理
Sub Macro1()
Dim s As String
s = "{""key1"":""value1""}"
Debug.Print s
Set objSC = New ScriptControl ' Microsoft Script Control 1.0
objSC.Language = "JScript"
objSC.AddCode "function parseJSON(s) { return eval('(' + s + ')'); };"
Dim objJSON As Object
Set objJSON = objSC.CodeObject.parseJSON(s)
Dim v As Object
' JSON Object の key1 を取得( obj.key1 )
Debug.Print CallByName(objJSON, "key1", VbGet)
Dim x As String
' String として取得
x = CallByName(objJSON, "key1", VbGet)
Debug.Print x
' リリース
Set objSC = Nothing
End Sub
■実行結果
{"key1":"value1"}
value1
value1