I am trying to connect via an XML RPC call to an API that takes as input a list of phrases, and gives as output– “Echoes back a struct of keyphrases each with a single item list of the original keyphrase.”
I am trying to use regular hashmap parsing code in the following way–
hMap = (HashMap<String, Integer>) untypedResult;
Set set = hMap.entrySet();
Iterator i = set.iterator();
while(i.hasNext()){
Map.Entry me = (Map.Entry)i.next();
resp.getWriter().println(me.getKey() + " : " + me.getValue() );
}
The output that I am getting is as follows–
Response for GetThesaurusKeyPhrases—-
mp3 : [Ljava.lang.Object;@76c3358b
britney spears : [Ljava.lang.Object;@9f07597
How do I obtain the values correctly? What I think is that I should parse each value (the me.getvalue part) correctly… but I am confused on how to go about doing this… Any help would be appreciated.
You might need to cast each key and value, ie
(String)me.getKey()and see what you get.From the snippet you’ve posted, it is possible that the
HashMap<String, Integer>in your cast is incorrect. The original HashMap may have been defined as simply aHashMaporHashMap<Object, Object>since your variable name isuntypedResult. I tried the following and it works as expected:The output for this block is: