Reputation: 3748
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?
Upvotes: 0
Views: 731
Reputation: 569
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");
Upvotes: 0
Reputation: 1322
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.
Upvotes: 2
Reputation: 476
double \\ = single \ in string ""
json.put("path","\\abx\\2010\\341\\test.PDF");
Upvotes: 0
Reputation: 82553
You need to escape \
.
Try json.put("path" , " \\abx\\2010\\341\\test.PDF");
You can learn more about it under Escape Sequences.
Upvotes: 0
Reputation: 769
Try like this
json.put("path" , "\\abx\\2010\\341\\test.PDF");
Upvotes: 1