我的服务通常会返回以下内容:
anyType{Acc1=96628; Code=E; OnArr=false; CanArr=true; Username=ANDERSON;}
然后我将其推向对象
details.Username = response.getProperty("Username").toString();
并按我需要的方式工作,直到收到没有用户名值的响应为止,返回如下:
anyType{Acc1=96628; Code=E; OnArr=false; CanArr=true; Username=anyType{};}
当我稍后调用details.Username时,它返回“ anyType {}”(作为字符串),而不是返回任何一个空字符串
你能告诉我我想念什么吗?
为清楚起见,我如何到达response
...
SoapObject request = new SoapObject(NAMESPACE, methodName);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("Details");
propertyInfo.setValue(details);
propertyInfo.setType(details.getClass());
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE, "Details", Details.class);
HttpTransportSE httpTransportSE = new HttpTransportSE(URL);
httpTransportSE.call(NAMESPACE + methodName, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
[编辑]
以下似乎可以解决问题;但是,我不太确定为什么还是正确的方法。
details.Username = response.getPrimitivePropertyAsString("Username");
答案 0 :(得分:0)
这似乎可以通过
解决details.Username = response.getPrimitivePropertyAsString("Username");
进入 SoapObject.java ,我也可以看到其背后的含义
/**
* Get the toString value of a property without chance of throwing an
* exception. An object can be provided to this method; if the property is
* not found, this object's string representation will be returned.
*
* @param defaultThing
* toString of the object to return if the property is not found
* @return the property toString if it exists; defaultThing toString if the
* property does not exist, if the defaultThing is null #EMPTY_STRING
* is returned
*/
public String getPropertySafelyAsString(final String namespace,final String name,
final Object defaultThing) {
Integer i = propertyIndex(namespace,name);
if (i != null) {
Object property = getProperty(i.intValue());
if (property != null) {
return property.toString();
} else {
return EMPTY_STRING;
}
} else {
if (defaultThing != null) {
return defaultThing.toString();
} else {
return EMPTY_STRING;
}
}
}