我有一个如下的json:
{"sentences":[{"trans":"something ru","orig":"english word","translit":"Angliyskoye slovo","src_translit":""}], "src":"en","server_time":69}
并解析它:
Function jsonDecode(jsonString As Variant)
Set sc = CreateObject("ScriptControl"): sc.Language = "JScript"
Set jsonDecode = sc.Eval("(" + jsonString + ")")
End Function
Set arr = jsonDecode(txt)
结果arr
包含如下值(在 Watches 中检查):
arr
- sentences (type: Variant/Object/JScriptTypeInfo)
- 0 (type: Variant/Object/JScriptTypeInfo)
- orig (type: Variant/String)
- trans (type: Variant/String)
...
- Item 1 (type: Variant/Object/JScriptTypeInfo)
- orig (type: Variant/String)
- trans (type: Variant/String)
...
- server_time
- src
arr.src
效果很好,但我怎么能得到arr.sentences(0).trans
?首先,VBA 替换sentences
为Sentences
,其次(当我尝试手动更改 json 时)它仍然不允许使用sentenses(0)
.