问题
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>
my xml part from webservice is that one.Im trying to access my friendlist by parsing.I couldnt understand ..when im debugging it broke in "SoapObject object = (SoapObject)wizardobject.getProperty(i)"..I want to know how can i parse one list that i take from webservice??Thank you for your help in advance...
回答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;
}
Hi guys, After so many effort i have found my answer..I can parse my array with above code..Thank u for interest..
回答2:
Are you sure that wizardobject.getProperty(i)
returns a SoapObject?? I would try with a String or just debug it without doing the casting and see what kind of object it is.
Check this -> SoapObject documentation
By the way it's handier if you post the error stack trace.
来源:https://stackoverflow.com/questions/10807150/how-to-parse-in-android-application-arraylist-from-php-webservice