1

如何将多维 sun.org.mozilla.javascript.internal.NativeArray 转换为相应的多维 Java 数组?

var verA=4;
var verB= [1234.000000,456.000000,7899.000000,14200.000000];
var arrayC= [
[
["tmp/a111"],
["tmp/a222.png","tmp/a333.png"],
["tmp/a444","tmp/a555.png","tmp/a666.png","tmp/a777.png"]],
[
["tmp/b111.png"],
["tmp/b222","tmp/b333.png"],
["tmp/b444.png","tmp/b555.png","tmp/b666.png","tmp/b777.png"]]};

我可以转换 verA 但很难转换 verB 和 arraC 这是我的代码。

ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("JavaScript");  

scriptEngine.eval(javaScriptStringAbove);
Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
System.out.println(bindings.keySet());// prints the ver names

Double verA = ((Double)bindings.get("verA")); // this works fine
Object verB[] = ((Object[])bindings.get("verB")); //error
Object verB[][][] = ((Object[])bindings.get("arrayC")); //error

我收到这个错误

java.lang.ClassCastException:sun.org.mozilla.javascript.internal.NativeArray 无法转换为 [Ljava.lang.Object;

4

0 回答 0