0

I had a scenario where I need to give back slash for a key in JSON put method like below

json.put("path" , " \\abx\2010\341\test.PDF");

The value I gave for path key shows error.

How to handle this case?

Raghav Sood
  • 80,914
  • 21
  • 183
  • 190
  • The answers below are mostly correct, except to have double-slashes at the beginning, they'll both need to be escaped, a la: `\\\\abx` – Jonathan M Jun 22 '16 at 18:08

5 Answers5

2

You need to write double slash instead of one: \\ So your code become:

json.put("path" , " \\\\abx\\2010\\341\\test.PDF");

You can learn more about escaping special characters in this answer.

Community
  • 1
  • 1
Atef
  • 1,153
  • 12
  • 24
1

Try like this

json.put("path" , "\\abx\\2010\\341\\test.PDF");
Adizbek Ergashev
  • 597
  • 6
  • 17
0

You need to escape \.

Try json.put("path" , " \\abx\\2010\\341\\test.PDF");

You can learn more about it under Escape Sequences.

Raghav Sood
  • 80,914
  • 21
  • 183
  • 190
0

double \\ = single \ in string ""

json.put("path","\\abx\\2010\\341\\test.PDF");
OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
Rifan
  • 374
  • 4
  • 15
0

If you want to show like this, JSON file should be as below.

"path" : " \\abx\2010\341\test.PDF"

JSON also \ represent as \ in java special characters. Then java code should be as below.

json.put("path" , " \\\\abx\\2010\\341\\test.PDF");

Gayan Chinthaka
  • 389
  • 5
  • 4