我正在尝试解析 REXP 输出。我已经将结果转换为 java 对象。但是我无法获取对象内部的值。对象 m 包含:
[1, 1, 3, 1, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
[9.12324245]
[1212,1234,4343]
[3.456]
我需要将这些值放入数组中以进行进一步处理
这里有什么帮助真的很棒吗?代码片段如下:
REXP kmv = connection.eval(kmeans);
HashMap<String, Object> j = (HashMap<String, Object>) kmv.asNativeJavaObject();
Set<Entry<String, Object>> set = j.entrySet();
Iterator<Entry<String, Object>> i = set.iterator();
while(i.hasNext()) {
Map.Entry<String, Object> me = (Map.Entry<String, Object>)i.next();
String key = (String) me.getValue();
Object m = (Object)me.getKey();
}
答案很简单
// Back to the basics of decoding an object :)
if (m.getClass().isArray()) {
if (m instanceof double[]) {
value = Arrays.toString((double[])m);
} else if (m instanceof int[]) {
value = Arrays.toString((int[])m);
}
}