1
       byte[] jsonData = Files.readAllBytes((Paths.get("txt.json")));

        String data = new String(jsonData,"UTF-8");
        data= data.replaceAll("[\\r\\n]+", "");
        data= data.replaceAll("\\t", "");

        data= data.replaceAll("\\\\","");
        response.setResponse(data);

data i am getting like this

       \"abs\": \"abc\",\"dff\": [{\"dff\": [{\"rtr\": \"dfg\",\"fdgdfg\"

but i need to remove slashes

        "abs": "abc","dff": [{"dff": [{"rtr": "dfg","fdgdfg"

please Help me what changes i need to do

user3639244
  • 61
  • 1
  • 7
  • `data= data.replaceAll("\\\"","\"");` should suffice. – Ken Y-N Dec 15 '16 at 07:11
  • Stop. What is the content of `txt.json`? Why do you need to replace escape characters? – OneCricketeer Dec 15 '16 at 07:13
  • Possible duplicate of [String replace a Backslash](http://stackoverflow.com/questions/5596458/string-replace-a-backslash) – user1211 Dec 15 '16 at 07:13
  • 2
    **How** are you "getting like this" ? Are you printing it on the console? Or are you using a json library to output it as JSON? (Or something else) I'm guessing you're outputing it using a JSON library as a string, which will add the backslashes back in, logically, to make it a valid json string. – Erwin Bolwidt Dec 15 '16 at 07:14
  • txt.Json File is JSON file, i am trying to read from json file and convert to String – user3639244 Dec 15 '16 at 07:39
  • *i am trying to read from json file and convert to String* **why? Why not convert it to JSON** – Scary Wombat Dec 15 '16 at 07:42
  • { "abc": "fgf", "fbdf": [{ "fdgdfg": [{ "fg": "gfdf", "fdgd": "dfgUs:"}, { "fidfg": "contafdgber","lafdgel": "(800) 206-9469" }], "ldfg": [{ "gfdd": "fgdfel", this is Txt.JSON – user3639244 Dec 15 '16 at 07:47
  • I have tried all methods , and Previously asked questions, but Slashes still displaying – user3639244 Dec 15 '16 at 07:51
  • i need to attach it into a JSON response, that is why i am trying to convert to string and attaching to JSON Response, is this the right Way? or how can i read from ?JSON file and attach it to a JSON response? – user3639244 Dec 15 '16 at 07:56
  • Show the real code that generates the output. We don't know what you mean with "attaching to json response". What kind of object is `response` on which you call `response.setResponse` ? What do you do with this `response` to get the output that you're showing above? – Erwin Bolwidt Dec 15 '16 at 09:45

1 Answers1

0

Use replace() instead of replaceAll():

data = data.replace("\\","");
Christian
  • 576
  • 1
  • 4
  • 16