vba把json转数组中_javascript – 在Excel VBA中解析JSON对象数组
您可以使用ScriptControl对象创建一个可以运行javascript的环境.如果您习惯在网页中使用JSON,那么这可能是一种简单的方法.例:Sub Tester()Dim json As StringDim sc As ObjectDim oSet sc = CreateObject("scriptcontrol")sc.Language = "JScript"json = {get yo
您可以使用ScriptControl对象创建一个可以运行javascript的环境.如果您习惯在网页中使用JSON,那么这可能是一种简单的方法.
例:
Sub Tester()
Dim json As String
Dim sc As Object
Dim o
Set sc = CreateObject("scriptcontrol")
sc.Language = "JScript"
json = {get your json here}
sc.Eval "var obj=(" & json & ")" 'evaluate the json response
'add some accessor functions
sc.AddCode "function getSentenceCount(){return obj.sentences.length;}"
sc.AddCode "function getSentence(i){return obj.sentences[i];}"
Debug.Print sc.Run("getSentenceCount")
Set o = sc.Run("getSentence", 0)
Debug.Print o.trans, o.orig
End Sub
更多推荐

所有评论(0)