简体   繁体   English

在XMLRPC结果中使用HashMap

[英]Use HashMap in XMLRPC result

I am new in Android development, and I am trying to receive a HashMap in RESULT by using XMLRPC but every time it's crash the application, this is my code please advice me : 我是Android开发的新手,我试图通过使用XMLRPC在RESULT中接收HashMap,但每次崩溃应用程序时,这都是我的代码,请指教我:

  Object RESULT =  XMLRPCClient.callEx(methodname,new Object[] {params});
         Map FRESULT= (Map) RESULT; 

I have been dealing with this also and managed to get the values this way: 我也一直在处理这个并设法以这种方式获得价值:

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

I'm sure it's a mess, I'm noob in Java myself, but it worked for me. 我确定这是一团糟,我自己也是Java的noob,但它对我有用。 Hope it helps :) 希望能帮助到你 :)

Now the Application pass this peacefully after implementing : 现在,应用程序在实施后平稳地传递:

 Object RESULT = XmlRpcConnect.ServerCall_a(method,new Object[] {params});
          Map<String, Object> FRESULT= (HashMap<String, Object>) RESULT;

with some changes in my XmlRpcConnect Class: 在我的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;
                                }

but when trying to extract the values it's crash again , any advice : 但是当试图提取值再次崩溃时,任何建议:

              if (FRESULT.get("status") == null) {
                          result = (String) FRESULT.get("status");
                          toastDialog(result);
               }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM