如何从php webservice解析android应用程序arraylist

时间:2012-05-29 21:46:09

标签: android web-services soap xml-parsing

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)”..我想要要知道如何解析我从webservice获取的一个列表?提前感谢您的帮助...

2 个答案:

答案 0 :(得分:1)

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;
    }
你好,伙计们, 经过这么多的努力,我找到了答案。我可以用上面的代码解析我的数组。谢谢你的兴趣..

答案 1 :(得分:0)

您确定 wizardobject.getProperty(i)

返回一个SoapObject ??我会尝试使用String或只是调试它而不进行转换,看看它是什么类型的对象。

检查一下 - &gt; SoapObject documentation

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