gpt4 book ai didi

java - Android中的Ksoap2无法序列化

转载 作者:行者123 更新时间:2023-12-01 18:43:30 25 4
gpt4 key购买 nike

我在android中使用kso​​ap2

以字符串形式发送数字列表

但是有错误:

java.lang.runtimeException无法序列化

我搜索了此错误的解决方案,但结果没有改变

请帮帮我

public String Send(ArrayList<String> contactlist)
{
try{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
pi.setType(String.class);
pi.setName("contactlist");
pi.setValue(contactlist);
request.addProperty("contactlist", pi);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

// Creating SOAP envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
new MarshalBase64().register(envelope); // this line is for serialization

//You can comment that line if your web service is not .NET one.
envelope.dotNet = true;

envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport("http://10.0.2.2:54869/Service1.asmx");
androidHttpTransport.debug = true;
}
catch (Exception exception)
{
return exception.toString();
}
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
//String result = envelope.getResponse().toString();
return "";//result;
}
catch (Exception exception)
{
return exception.toString();
}

最佳答案

使用此类进行序列化

public class MarshalDouble implements Marshal {
public Object readInstance(XmlPullParser parser, String namespace,
String name, PropertyInfo expected) throws IOException,
XmlPullParserException {

return Double.parseDouble(parser.nextText());
}

public void register(SoapSerializationEnvelope cm) {
cm.addMapping(cm.xsd, "double", Double.class, this);

}

public void writeInstance(XmlSerializer writer, Object obj)
throws IOException {
writer.text(obj.toString());
}
}

将此行添加到信封

    envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
MarshalDouble md = new MarshalDouble();
md.register(envelope);

关于java - Android中的Ksoap2无法序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18943475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com