我正在使用ksoap,我想将我的android收集的位置信息发送到ksoap。我想尝试避免制作马歇尔课程等,是否有一种简单的方法来序列化并将双重发送到我的肥皂xml?我已经尝试使用String.valueof然而它抛出一个错误,所以我假设我不能使用它。还有一个问题,我正在将double传递给十进制类型的xml?
这是我发送给的xml文件:
<s:element name="Customerlocation_AddNew">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Token" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="Username" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="latitude" type="s:decimal" />
<s:element minOccurs="1" maxOccurs="1" name="longitude" type="s:decimal" />
<s:element minOccurs="1" maxOccurs="1" name="StatusId" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
到目前为止和我的java代码:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set
request.addProperty("Username", username); // variable name, value. I
// got
request.addProperty("latitude", String.valueOf(Latitude));
request.addProperty("longitude", String.valueOf(Longitude));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11); // put all required data into a soap
envelope.dotNet = true;
envelope.setOutputSoapObject(request); // prepare request
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope); // send request
System.out.println("HERE IS THE ENVELOPE "
+ envelope.getInfo("User", "Password"));
SoapObject result = (SoapObject) envelope.getResponse(); // get
System.out.println(result);
答案 0 :(得分:1)
你为什么要避免使用元帅?! MarshalFloat专门用于运输浮子。如果你真的想要没有元帅 - 请看MarshalFloat实施!在你的情况下,你应该使用这样的东西:
request.addProperty("longitude", new BigDecimal(Longitude).toString())
编辑: 记录您的请求\响应以找出错误:
Log.d("test", "request: " + httpTransport .requestDump);
Log.d("test", "response: " + httpTransport .responseDump);
尝试以下方法获取结果对象:
SoapObject result = (SoapObject) envelope.bodyIn;
希望这会有所帮助。祝你好运!