0

I am trying to send a double value via Ion Library call. I can't seem to send a double value and this messes up my code. I am trying to convert INR to USD and vice versa via an api call. My double value is 'amount'.

Ion.with(context)
                .load("POST",url)
                .setBodyParameter("amount",amount)
                .asString()
                .setCallback(new FutureCallback<String>() {
                    @RequiresApi(api = Build.VERSION_CODES.N)
                    @Override
                    public void onCompleted(Exception e, String result) {
                        try {
                            JSONObject o = new JSONObject(result);
                            if (o.getString("code").equals("200")) {
                                PriceModel.Instance().setUSDEquivalent(o.getDouble("result"));
                            }

                        } catch (JSONException e1) {
                            e1.printStackTrace();
                        }
                    }
                });
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Varun Joshi
  • 97
  • 1
  • 6

1 Answers1

0

You need to convert double to String as ION only allows String as body parameter. So you can do as follow:

Ion.with(context)
.load("POST",url)
.setBodyParameter("amount",String.valueOf(amount))..

Reference: IonRequestBuilder.setBodyParameter(String name, String value)

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153