在 XMLRPC 结果中使用 HashMap

发布于 2024-10-18 08:05:05 字数 217 浏览 3 评论 0原文

我是 Android 开发新手,我尝试使用 XMLRPC 在 RESULT 中接收 HashMap,但每次应用程序崩溃时,这是我的代码,请建议我:

  Object RESULT =  XMLRPCClient.callEx(methodname,new Object[] {params});
         Map FRESULT= (Map) 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 :

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾北清歌寒 2024-10-25 08:05:05

我也一直在处理这个问题,并设法以这种方式获取值:

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 菜鸟,但它对我有用。希望它有帮助:)

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. Hope it helps :)

ι不睡觉的鱼゛ 2024-10-25 08:05:05

现在应用程序在实现后和平地传递了这个:

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

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:

@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);
               }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文