0

I am using HTTP Client to send different kinds of requests (GET, PUT, POST, DELETE) where I am sending the JSON as a data to post with different requests.

I have a JSON data like:

{ "createdByID": "100000", "createdByName": "Admin", "modifiedByID": "100000", "modifiedByName": "Admin" }

Now, to store this JSON into a string, I have to add double quotes wherever necessary so that this can be stored as

String jsonData = "{" + "\"" + "createdByID" + "\"" + ":" + "\"" +  "100000" + "\"" + "," + "\"" + "createdByName" + "\"" + ":" + "\"" + "Admin" + "\"" + "," + "\"" + "modifiedByID" + "\"" + ":" + "\"" +  "100000" + "\"" + "," + "\"" + "modifiedByName" + "\"" + ":" + "\"" + "Admin" + "\"" + "}"

Does anyone use any tool/utility to convert the JSON data such that it can be stored in a string object?

Please share if anyone has already done this

Srivastava
  • 3,500
  • 12
  • 46
  • 74
  • Quite unclear what you're asking. It is a string, it doesn't need any conversions. If you mean to add escapings to quotes, use any text editor's search and replace. And there is no need for all the separate strings and pluses – Sami Kuhmonen Aug 09 '16 at 04:58
  • If you want to convert JSon object to String then you can use any JSON parsing library. – Sachin Gupta Aug 09 '16 at 05:04
  • I think that he meant that the field is being handled as JSON and he need it as plain String, in this case this answer can be useful: http://stackoverflow.com/a/15665014/3211175 – AlexITC Aug 09 '16 at 05:24
  • Can you not do `jsonData = jsonObj.toString()` function leveraging the built in `toString()` method? – Vivek Pradhan Aug 09 '16 at 07:12

1 Answers1

0

Hey if you store the json as a sting in your code then only you need to add double codes.

Try to read json from a text file , then you don't need to add double quotes and other stuffs.

More over java does not consider double quotes after compiling your code.

Karthikeyan KR
  • 1,134
  • 1
  • 17
  • 38