【问题标题】:How to parse in android application arraylist from php webservice如何从php webservice解析android应用程序arraylist
【发布时间】:2012-06-04 03:34:33
【问题描述】:
public static UserFriendListContainer getFriendList(SoapObject wizardobject)//TESTED
    {
        UserFriendListContainer container= new UserFriendListContainer();


        List<UserFriendListModel> list= new ArrayList();    

        String currobj= wizardobject.getProperty("FriendListResult").toString();

        Log.v("CurrentObjet+++++++",currobj.toString());




        container.setParserResult(currobj);



        SoapObject result = (SoapObject)wizardobject;
        for(int i=0;i<result.getPropertyCount();i++)
        {

                SoapObject object = (SoapObject)wizardobject.getProperty(i);//here it is break

Log.v("result:::::",result.toString());
                Log.v("obj:::::",object.toString());
                Log.v("friendID",object.getProperty("friendid").toString());
                String friendID=object.getProperty("friendid").toString();

                Log.v("friendname",object.getProperty("friendname").toString());
                String friendname=object.getProperty("friendname").toString();

                Log.v("lastaction",object.getProperty("lastaction").toString());
                String lastaction=object.getProperty("lastaction").toString();

                Log.v("friendphoto",object.getProperty("friendphoto").toString());
                String friendphoto=object.getProperty("friendphoto").toString();

                UserFriendListModel model=new UserFriendListModel();
                model.setfriendID(friendID);
                model.setfriendName(friendname);
                model.setfriendPhoto(friendphoto);
                model.setLastAction(lastaction);

                list.add(model);
            }
            container.setList(list);

        return container;
    }

}

-----
<message name="FriendListRequest"/>
<message name="FriendListResponse">
<part name="FriendListResult" type="tns:FirendListArray"/>
</message> 

我的 webservice 的 xml 部分就是那个。我试图通过解析访问我的好友列表。我无法理解 ..当我调试它时它打破了“SoapObject object = (SoapObject)wizardobject.getProperty(i)”..我想要知道如何解析我从 web 服务中获取的一个列表?谢谢您提前提供的帮助...

【问题讨论】:

    标签: android web-services soap xml-parsing


    【解决方案1】:

    您确定 wizardobject.getProperty(i)

    返回一个 SoapObject??我会尝试使用字符串,或者只是在不进行强制转换的情况下对其进行调试,看看它是什么类型的对象。

    检查这个 -> SoapObject documentation

    顺便说一句,如果您发布错误堆栈跟踪会更方便。

    【讨论】:

    • 06-03 11:49:17.187: V/RESPONSE OF getFriendList:(275): FriendListResponse{FriendListResult=[FirendList{friendid=1;朋友照片=profile1.jpg;朋友名=Onur Enis Bozdemir; lastaction=Giriş Yaptı - (5 dk önce); }, 好友列表{friendid=3;朋友照片=profile5.jpg;朋友名=测试测试; lastaction=Giriş Yaptı - (5 dk önce); }]; 06-03 11:49:31.159: D/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol in my log cat 我有这些结果..我不能拿我的清单跨度>
    【解决方案2】:
    public static UserFriendListContainer getfriendlist(SoapObject wizardobject) throws XmlPullParserException, IOException {
    
            UserFriendListContainer container= new UserFriendListContainer();
            UserFriendListModel model = new UserFriendListModel();
    
             List<UserFriendListModel> list= null;
              list=new ArrayList<UserFriendListModel>();
            Vector vector = (Vector) wizardobject.getProperty("FriendListResult");
    
              Log.v("vector+++++++",vector.toString());
              System.out.println("vectorsize+++++++"+vector.size());
    
              int count=vector.size();
    
    
              for (int i = 0; i <count; ++i) { 
    
            SoapObject test=(SoapObject)vector.get(i);
    
    
              Log.v("test+++++++",test.toString());  
    
                   Log.v("friendid",test.getProperty("friendid").toString());
                    String friendID=test.getProperty("friendid").toString();
    
                    Log.v("friendname",test.getProperty("friendname").toString());
                    String friendname=test.getProperty("friendname").toString();
    
                    Log.v("lastaction",test.getProperty("lastaction").toString());
                    String lastaction=test.getProperty("lastaction").toString();
    
                    Log.v("friendphoto",test.getProperty("friendphoto").toString());
                    String friendphoto=test.getProperty("friendphoto").toString();
    
                    model.setfriendID(friendID);
                    model.setfriendName(friendname);
                    model.setfriendPhoto(friendphoto);
                    model.setLastAction(lastaction);
    
                    list.add(model);
                }
                container.setList(list);
                System.out.println("List==="+list);
    
    
             return container;
        }
    

    大家好, 经过这么多努力我找到了答案..我可以用上面的代码解析我的数组..谢谢你的兴趣..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-04
      • 2013-06-08
      • 1970-01-01
      • 2012-11-09
      • 1970-01-01
      • 1970-01-01
      • 2013-02-08
      • 1970-01-01
      相关资源
      最近更新 更多