2

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?

user1368800
  • 131
  • 4
  • 14
  • Try to get the Property `Recipient` & then loop it again to get `IsRead` property like you have done for `MessageInstance`. I think you will get it easily. – Shashank_Itmaster May 11 '12 at 03:47

1 Answers1

7

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");
Oguz Ozkeroglu
  • 3,025
  • 3
  • 38
  • 64
  • I'm still getting the same error... It's weird, I've tried all the ways of converting a string to boolean that I've could find... I've also tried simply getting it to a string first, and then converting that string, but I still get the same error... – user1368800 May 11 '12 at 13:48
  • 1
    First this: SoapObject soRecipient = (SoapObject) mail.getProperty("Recipient"); – Oguz Ozkeroglu May 11 '12 at 13:49
  • 1
    After this: boolean isRead = Boolean.parseBoolean(soRecipient.getPropertyAsString("IsRead")); – Oguz Ozkeroglu May 11 '12 at 13:50
  • Oh, damn.. I'm an idiot :) I knew this, just forget that is was deeper nested than the others... Thanks for correcting my brain-fart :) – user1368800 May 11 '12 at 14:06
  • Hi Guys, In my case the response that i get from Webservice is dynamic(i.e), For instance, it may contain a certain property or may not. In that scenario, How can i handle this illegal Property exception. – Nandagopal T Aug 01 '12 at 07:05
  • SoapObject has `hasProperty(propertyName)` method that returns a boolean value. You can use this with `if-else` – Oguz Ozkeroglu Aug 01 '12 at 08:18
  • @OguzOzkeroglu: Can you please help me for Soap Object issue i am want to fetch values from one soap Object which is nested. Or can you tell me how to access the value part soapObject? – Mahaveer Muttha Apr 10 '13 at 12:22
  • @user1368800: need help for SoapObject Parsing can you please tell me how get value part from SoapObject? – Mahaveer Muttha Apr 10 '13 at 12:43
  • @OguzOzkeroglu: yes i am getting values in SoapObject in Value part of object but i am unable to retrive from it. like in value part there is elementData in their value part again i get some values and so on its nested.... – Mahaveer Muttha Apr 10 '13 at 15:08