- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的服务通常会返回类似以下内容:
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{}”(作为字符串),而不是返回空字符串
你能告诉我我错过了什么吗?
为了清楚地说明我如何得到回复
...
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");
最佳答案
这似乎已解决
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;
}
}
}
关于java - 如何正确处理来自Web服务的anyType()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55025580/
您好,我正在编写这个程序,我正在尝试弄清楚如何比较数组中的两个项目以找到最大的项目。 public static > T getLargest(T [] a, int low, int high){
我正在使用答案 How do I create a new AnyType[] array? 中的代码。我的问题是如何初始化这个数组。当我尝试运行此代码时,我在 Clear() 上遇到空指针异常,我认
创建 UIBUttons 操作时,默认为 AnyType。为什么它是默认的,为什么它是一个选项?不应该只是 UIButton 吗? 最佳答案 我们可以将 任何 类型的 UIControl 连接到 IB
在这种情况下,最佳做法是什么?我想要一个与原始数组具有相同类型和长度的未初始化数组。 public static > void someFunction(AnyType[] someArray) {
我有一个由另一个应用程序提供的现有 XML 文件,看起来类似于: RootName
以下代码会导致转换异常,我不确定原因。 ParameterValueList 中的对象应该急切地解码为 JAXB 对象 ParameterValueStruct,但事实并非如此。一切都是直接从 soa
我正在尝试在 WCF 外部使用 DataContractSerializer 来序列化一个对象。本例中的对象继承自 CollectionBase 周围的旧通用包装器,例如 [KnownType(typ
尝试在 Swift 中制作并洗牌一副牌,该牌组由名为 cardDeck 的数组中的 Card 对象组成。然后我想洗牌。相关代码: var cardDeck = [card]() for
我的问题是我有一个 MessageList 类型的类,它包含 Message 项,定义如下: 我的消息类看起来像
我是编程界的新手,所以我只需要一些帮助。我必须在 android 上使用 web 服务。我已经做了一个工作正常的,但是当我必须传递一个参数时,问题就发生了。我不确定我做错了什么。 这是 AsyncTa
我有一个模式片段看起来像 hyperjaxb3 生成的
假设我有一个用户模式,它将“爱好”链接到它,作为一个数组字符串。 我最近从 MongoDB 切换到 SQL,所以,我的第一个想法是像 Mongo 一样接近它,并做出这样的东西; var userSch
xsd 在这里: http://www.iana.org/assignments/xml-registry/schema/epp-1.0.xsd 我不想修改 XSD(由第三方维护)或 XJC 生成的类
这是我的异步代码 @Override protected SoapObject doInBackground(String... params) { try { SoapObject requ
如您所知,.NET 框架中有一个通用类 List。我想用 C++ 编写一个通用类列表,我想在我的列表中存储指向一个类型的指针。这是类和测试程序的头文件和源代码: // header template
我有这个XML文件 和这个XSD 架构
我正在阅读有关 XML、XML-Schema、DTD 的资料,但我并不真正理解 xsd:any 和 xsd:anyType 之间的区别。 有人可以向我解释一下或指出一些好的文章吗? (请不要链接到 X
喜欢ISNULL函数中的参数吗? 我们可以用来定义的东西: create function getvalue ( @param1 varchar(max), @param2 varch
在使用 DataContractSerializer 时,我得到了很多我不想使用的 namespace 的额外属性。我在另一个项目中生成了一个类似的数据结构,没有所有额外的标记,所以我知道它是可能的。
我在我的 Android 应用程序中调用 Web 服务,方法是 getGramaNiladhariData(),我得到的结果是 SoapObject。 result = (SoapObject) en
我是一名优秀的程序员,十分优秀!