[英]Use HashMap in XMLRPC result
我是Android开发的新手,我试图通过使用XMLRPC在RESULT中接收HashMap,但每次崩溃应用程序时,这都是我的代码,请指教我:
Object RESULT = XMLRPCClient.callEx(methodname,new Object[] {params});
Map FRESULT= (Map) RESULT;
我也一直在处理这个并设法以这种方式获得价值:
try {
Object[] answer = (Object[]) client.call("call", sessionId, method, params);
HashMap map = (HashMap) answer[0]; // get first item of the response because in my case the response was an array of Objects with one item in it holding the HashMap
Object[] records = (Object[]) map.get("records"); // I only needed values from "records" key
for (int i = 0; i < records.length; i++) {
HashMap record = (HashMap) records[i]; // create another map from the records values, in my case uid's of categories
Category cat = new Category(); // creating new instance of my Category class
cat.setCatUid((String) record.get("uid")); // calling a method of the Category class to set Uid to the value from record HashMap
m_categories.add(cat); // this adds it to my ArrayList<Category>
}
} catch (XMLRPCException e) {
Log.e(method, "Exception", e);
}
我确定这是一团糟,我自己也是Java的noob,但它对我有用。 希望能帮助到你 :)
现在,应用程序在实施后平稳地传递:
Object RESULT = XmlRpcConnect.ServerCall_a(method,new Object[] {params});
Map<String, Object> FRESULT= (HashMap<String, Object>) RESULT;
在我的XmlRpcConnect类中进行了一些更改:
@SuppressWarnings("unchecked");
public static Object ServerCall_a(String method, Object[] params){
XMLRPCClient client = new XMLRPCClient(server);
HashMap<String, Object> result=null;
try{
result = (HashMap<String, Object>) client.callEx(method, params);
}
catch(XMLRPCFault f){
// result = ("Fault message: " + f.getMessage());
}
catch(XMLRPCException e){
// result = ("Exception message: " + e.getMessage());
}
return result;
}
但是当试图提取值再次崩溃时,任何建议:
if (FRESULT.get("status") == null) {
result = (String) FRESULT.get("status");
toastDialog(result);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.