0

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.

UmAnusorn
  • 10,420
  • 10
  • 72
  • 100
R Besar
  • 574
  • 1
  • 5
  • 12
  • where are you getting this json data from or creating from ? – HourGlass Sep 29 '16 at 05:25
  • json string is in that format only after parsing that will get delected http://stackoverflow.com/questions/19176024/how-to-escape-special-characters-in-building-a-json-string – Mahesh Giri Sep 29 '16 at 05:52

1 Answers1

0

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

Mohit Trivedi
  • 699
  • 3
  • 13