R Besar
R Besar

Reputation: 644

Android : gson.toJson() doesn't give standard json

When i tried to convert Object to json format using gson.toJson(myObject) it gives me not standard json format

Output currently : {\"objects\":[],\"type\":\"price\"}

what should i need is like this : {"objects":[],"type":"price"}

below how i convert my Object to json :

Gson gson = new Gson();
                String dataJson = gson.toJson(MyObject);
                System.out.println("LOG : " + dataJson);

My question is : How to make normal json format using Gson? thanks.

Upvotes: 0

Views: 199

Answers (1)

Mohit Trivedi
Mohit Trivedi

Reputation: 729

Hi R Besar,

        String json="{\\\"objects\\\":[],\\\"type\\\":\\\"price\\\"}";
        Log.d("TAG","Old Json: "+json);

        String newJson=json.replace("\\","");
        Log.d("TAG","New Json: "+newJson);

OUTPUT

{\"objects\":[],\"type\":\"price\"}
{"objects":[],"type":"price"}

I think this will help you

Upvotes: 0

Related Questions