从SoapObject获取布尔值(kSOAP2)

时间:2012-05-11 01:26:00

标签: android boolean ksoap2

我正在尝试从SoapObject获取一个布尔值,我是在Android中使用kSOAP2从Web服务器的响应得到的...

我已经在SoapObject中保存了Web调用的响应:

SoapObject sResult = (SoapObject)envelope.bodyIn;

我正在迭代响应并抓住值

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

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

    /*Getting the values here*/   
}

邮件SoapObject与此类似:

  

MessageInstance = anyType的{AUTHORNAME =Børnehaven;   CreatedAtUtc = 2012-04-10T18:30:00; ID = 631; MessageBody = Husk i morgen;   收件人= {anyType的全名= NULL; ID = 2104535421; IsRead = TRUE;   ReadAtUtc = 2012-04-10T18:30:00; }; };

我遇到的唯一值就是“IsRead”值,我想将其存储为布尔值...

我尝试了一些事情:

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

但我一直在接受:

  

W / System.err(1283):java.lang.RuntimeException:非法属性:   IsRead

获得它的正确方法是什么?

1 个答案:

答案 0 :(得分:7)

试试这段代码:

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");