使用ScriptObjectMirror将数组结果从JavaScript转换为有用的东西 [英] Casting Array Result From JavaScript to Something Useful Using ScriptObjectMirror
本文介绍了使用ScriptObjectMirror将数组结果从JavaScript转换为有用的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个返回字符串数组的JS 函数
,我应该如何将其强制转换为有用的类型(我在考虑Java数组还是Collection类)?我注意到返回类型始终是 ScriptObjectMirror
,它具有有趣的 to(Class<?> clazz)
方法,但是我不确定它的用途.我已经检查了其他几个StackOverflow问题,但是没有一个有用的.你能举个例子吗?
If I have a JS function
that returns an array of strings, how should I go about casting it to a useful type (I'm thinking either a Java array or Collection class)? I've noticed that the return type is always a ScriptObjectMirror
which has an interesting to(Class<?> clazz)
method, but I'm uncertain on it's use. I've checked several other StackOverflow questions, but none were useful. Can you show an example?
推荐答案
好,这对我有用:
ScriptObjectMirror result = (ScriptObjectMirror) function.invokeFunction("nameGen", 10);
String[] strings = result.to(String[].class);
这篇关于使用ScriptObjectMirror将数组结果从JavaScript转换为有用的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文