gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:11:26 35 4
gpt4 key购买 nike

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>

我来自 web 服务的 xml 部分是那个。我试图通过解析访问我的 friend 列表。我无法理解..当我调试它时它在“SoapObject object = (SoapObject)wizardobject.getProperty(i)”中崩溃了..我想要知道如何解析我从网络服务中获取的一个列表??提前感谢您的帮助...

最佳答案

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

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

关于android - 如何从 php webservice 在 android 应用程序 arraylist 中解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10807150/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com