Get boolean from SoapObject (kSOAP2)
android, boolean, ksoap2
Solution
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");
Problem
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?