2017-02-05 71 views
1

我正試圖解析一個REXP輸出。我已經將結果轉換爲一個java對象。但是我無法獲得對象內的值。 物體M包含:如何從Java對象(REXP對象)獲取值?

[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();    
} 

回答

0

答案很簡單

   // 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); 
       } 
      }