我在从Date
响应中获取java.util.Date
(ksoap2
)对象时遇到问题。这是响应XML:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header></s:Header>
<s:Body>
<UpdateLocationResponse xmlns="http://tempuri.org/">
<UpdateLocationResult>2012-05-07T13:34:34.7693883-04:00</UpdateLocationResult>
</UpdateLocationResponse>
</s:Body>
</s:Envelope>
以下是我用于初始化信封和请求的代码(由于安全原因,使用 * * 而不是真实姓名):
static final String NAMESPACE = "http://tempuri.org/";
static final String URL = "http://****************.svc";
envelope.addMapping(NAMESPACE, "UpdateLocationResult", Date.class,
new MarshalDate());
MarshalDate mdate = new MarshalDate();
mdate.register(envelope);
envelope.implicitTypes = true;
HttpTransportSE trans = new HttpTransportSE(URL);
trans.debug = true;
trans.call(SOAP_ACTION, envelope);
Object r = envelope.getResponse(); // r is always SoapPrimitive!!!
// I want it to be a java.util.Date
我已尝试过命名空间,属性名称和marshallers的所有组合,但无济于事。我总是从SoapPrimitive
envelope.getResponse()
我做错了什么?
答案 0 :(得分:0)
它不是一个字符串吗?尝试使用SimpleDateFormat
这可能对你有用:
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
String strDate = response.toString();