开发者

A simple way to serialise a double?

开发者 https://www.devze.com 2023-04-07 04:58 出处:网络
I am using ksoap and I want to send location information gathered by my android to ksoap. I want to try and avoid making a marshall class etc, is there a simple way to serialise and send the double to

I am using ksoap and I want to send location information gathered by my android to ksoap. I want to try and avoid making a marshall class etc, is there a simple way to serialise and send the double to my soap xml? I've tried using String.valueof however it throws an error so i assume I cannot use that. Also is it an issue that I'm passing a double to the xml of type decimal?

This is the xml file I am sending to:

<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>

and my java code so far:

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 a开发者_StackOverflow社区ll 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);


Why do you want to avoid using Marshal?! There is an implementation MarshalFloat especially for transporting floats. If you really want to go without Marshal - look at MarshalFloat implementation! In your case you should use something like this:

request.addProperty("longitude", new BigDecimal(Longitude).toString())

EDIT: log your request\response to find out what is wrong:

 Log.d("test", "request: " + httpTransport .requestDump);
 Log.d("test", "response: " + httpTransport .responseDump);

And try the following to obtain result object:

SoapObject result = (SoapObject) envelope.bodyIn;

Hope this helps. Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号