2

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

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

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; 编号=631;MessageBody=Husk i morgen; 收件人=anyType{FullName=null; id=2104535421;读=真;ReadAtUtc=2012-04-10T18:30:00; }; };

我无法获取的唯一值是“IsRead”值,我想将其存储为布尔值......

我尝试了几件事:

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

但我不断得到:

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

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

4

1 回答 1

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");
于 2012-05-11T12:27:56.137 回答