Jhaman Das
Jhaman Das

Reputation: 1114

JSON object adding extra back slash

What i am doing currently creating json object and passing to volley for service call, its placing back slash in jsonObject in key value result is getting 404. following is my code and creating jsonObject.

 JSONObject params = new JSONObject();
 params.put("user_name", "[email protected]");
 params.put("password", "6e7a0497daffa4554cc28973bc129632");
 params.put("key", "ly9jCDu03/1:3M1");  

And as i debuged the josnObject adding extra \ (forward slash in my key json object thats why service break through as 404) following is json getting through debug.

{
  "password": "6e7a0497daffa4554cc28973bc129632",
  "user_name": "[email protected]",
  "key": "ly9jCDu03\/1:3M1"
}     

So how to remove this \ extra forward slash as instead of this ly9jCDu03/1:3M1 its making ly9jCDu03\/1:3M1 any help could be appreciated.

Thanks in Advance

Upvotes: 0

Views: 4180

Answers (2)

rohit salaria
rohit salaria

Reputation: 196

when json convert key value to string "ly9jCDu03/1:3M1" it adds extra '\' to represent the '/' as '/' is a special character and to represent that u need '\'

it is just like when u want to print '/n' in c++ u need to add extra '\'

Upvotes: 1

Farhan Wazir
Farhan Wazir

Reputation: 31

Java is encoding your JSON string for sending to end point. Slash (/) is not an issue, if request not build with proper manners and there is any problem at Java end then you receive 500 Internal Server Error or volley error.

Be confident on your code and check service.

Upvotes: 1

Related Questions