0

I'm trying to connect to server through a web-service. In this web service, i'm passing list of namevaluepairs. Now problem is namevaluepair only accepts (String,String) parameters. Where as my server expects a double value. So I can not convert my double to string and pass it ( as server would see as a string and will throw a 'Improper format' Error.

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("Name", mydoublevalue));  
        JSONArray jsonobj = jsonParser.makeHttpRequest_array(url,type, nameValuePairs);

Is there any way out?. or do I have to change server's double type to string so that server would expect string instead of double?

user3527400
  • 35
  • 1
  • 8

2 Answers2

0

This will convert the double value to String.

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("Name", String.valueOf(mydoublevalue)));  
            JSONArray jsonobj = jsonParser.makeHttpRequest_array(url,type, nameValuePairs);
Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
  • that's what i'm saying. My server wants double, whereas it would a pass string ( of my double) hence type mis-match. – user3527400 Feb 04 '15 at 10:29
  • Then its not possible its the duty of server to convert the parameters value in desired type which it wants. I think server will automatically assume that value as double. – Gopal Singh Sirvi Feb 06 '15 at 08:32
0

Finally I managed to do it from Android side only.

Here's What I did. I created my own class that implemets NameValuePair interface. There you can have STRING, DOUBLE instead of STRING,STRING in BasicNameValuePair. Here is the code.

import org.apache.http.NameValuePair;

public class DoubleNameValuePair implements NameValuePair {

 String name;

    double value;

    public DoubleNameValuePair(String name, double value) {
        this.name = name;
        this.value = value;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getValue() {
        return Double.toString(value);
    }

}

Then when you want to add to list, just do

nameValuePairs.add(new DoubleNameValuePair("Latitude",21.3243));
user3527400
  • 35
  • 1
  • 8