Remove value quotes in Jsonobject on Android

Asked

Viewed 184 times

-2

In my Android project I need to generate the following Json result:

{"value":164.40}

However, how to remove the quotes from the String result?

JSONObject json = new JSONObject();
json.put("value", "164.40");

The return is coming with quotes:

{"value":"164.40"}
  • Ever tried to get past the Apas json.put("value", 164.40);?

  • Which package you are using?

  • 1

    The value is a pre-formatted String return. I am using the org.json.Jsonobject package

  • If you did what I said json.put("value", 164.40); ?

  • Read what I wrote, it’s no use me putting it in hand...

  • You put in your question fixed data if it is a String being a text and that is your doubt you have to pass to number? is that your doubt? if you are not clear in your questions it is difficult to understand your doubt.

  • I passed as an example, "164.40" is a result of the type String (coming from elsewhere). But I have already solved with Leonardo.

Show 2 more comments

1 answer

0


Create a model class to receive the data, for Json, I recommend using the Gson (google, she is amazing):

Gson mGson = new Gson();
DadosModel mDados = new DadosModel();
mDados = mGson.fromJson(meuJson, DadosModel.class);

Its model class:

public class DadosModel
{
    private double value;

    public double getValue() {
        return value;
    }

    public void setValue(double value) {
        this.value = value;
    }
}

when you have a put, pass in the following format:

json.put("value", 164.40);
  • Thanks for the tip Leonardo. I was able to solve it in a simpler way using Gson: gson.fromJson("164.40", Object.class)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.