Get boolean from SoapObject (kSOAP2)

心已入冬 提交于 2020-01-04 05:37:09

问题


I'm trying to get a boolean value from a SoapObject, I've gotten from a response from a web server using kSOAP2 in Android...

I've saved the response form the web call in a SoapObject:

SoapObject sResult = (SoapObject)envelope.bodyIn;

and I'm iterating through the response and grabbing the values

SoapObject soapresults = (SoapObject)sResult.getProperty(0);

for (int i = 0; i < count; i++)
{
    SoapObject mail = (SoapObject)soapresults.getProperty(i);

    /*Getting the values here*/   
}

A mail SoapObject will be similar to this:

MessageInstance=anyType{AuthorName=Børnehaven; CreatedAtUtc=2012-04-10T18:30:00; Id=631; MessageBody=Husk i morgen; Recipient=anyType{FullName=null; Id=2104535421; IsRead=true; ReadAtUtc=2012-04-10T18:30:00; }; };

And the only value I'm having trouble grabbing is the "IsRead" value, which I want to store as a boolean...

I've tried a few things:

(Boolean)mail.getProperty("IsRead");
((Boolean) mail.getProperty("IsRead")).booleanValue();

But I keep getting:

W/System.err(1283): java.lang.RuntimeException: illegal property: IsRead

What is the correct way of getting it?


回答1:


Try this code snippet:

SoapObject soRecipient = (SoapObject) mail.getProperty("Recipient");

boolean isRead = Boolean.parseBoolean(soRecipient.getPropertyAsString("IsRead"));
String fullName = soRecipient.getPropertyAsString("FullName");
String id = soRecipient.getPropertyAsString("Id");
String readAtUtc = soRecipient.getPropertyAsString("ReadAtUtc");


来源:https://stackoverflow.com/questions/10544243/get-boolean-from-soapobject-ksoap2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!