Ich habe ein Json wie unten:Wie kann JSON mit VBA ohne externe Bibliotheken analysiert werden?
{"sentences":[{"trans":"something ru","orig":"english word","translit":"Angliyskoye slovo","src_translit":""}], "src":"en","server_time":69}
und es analysieren:
Function jsonDecode(jsonString As Variant)
Set sc = CreateObject("ScriptControl"): sc.Language = "JScript"
Set jsonDecode = sc.Eval("(" + jsonString + ")")
End Function
Set arr = jsonDecode(txt)
In Folge arr
Werte wie unten enthält (bei Uhren markiert):
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
funktioniert gut , aber wie kann ich arr.sentences(0).trans
bekommen? Erstens ersetzt VBA sentences
durch Sentences
, zweitens (wenn ich versucht habe, den Json manuell zu ändern), erlaubt es immer noch nicht, sentenses(0)
zu verwenden.
möglich Duplikat [Parsing JSON in Excel VBA] (http://stackoverflow.com/Fragen/6627652/Parsing-json-in-Excel-VBA) Schauen Sie sich [erste Antwort] (http://stackoverflow.com/a/7300926/1316573) –
[Parsing JSON mit VBA mit ** Beispieldatei **] (http://stackoverflow.com/questions/16817545/handle-json-object-in-xmlhttp-response-in-excel-vba-code/16851758#16851758) – Santosh
@DanielCook, meine Excel 2010 doe erkennt ScriptControl nicht von dieser Antwort. –