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
  • 81,899
  • 22
  • 187
  • 195
  • 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,294
  • 1
  • 14
  • 27
1

Try like this

json.put("path" , "\\abx\\2010\\341\\test.PDF");
Adizbek Ergashev
  • 732
  • 8
  • 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
  • 81,899
  • 22
  • 187
  • 195
0

double \\ = single \ in string ""

json.put("path","\\abx\\2010\\341\\test.PDF");
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Rifan
  • 424
  • 6
  • 17
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
  • 521
  • 6
  • 5