0

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

12
  • FWIW, it's harmless. In JSON (as in JavaScript), within a string literal, \/ means /. More: json.org The actual string represented does not have the backslash in it. Commented Mar 1, 2017 at 9:31
  • "...forward slash in my key json object thats why service break through as 404..." Then the service is broken, and that's what needs fixing. The JSON is entirely valid. Commented Mar 1, 2017 at 9:32
  • but i m getting 404 on reponse, while its working fine in postman, what the solution for this. @T.J.Crowder Commented Mar 1, 2017 at 9:32
  • Fix the thing that's breaking on perfectly valid JSON. Commented Mar 1, 2017 at 9:33
  • (BTW: You'll want to update the question to say what JSON library you're using, as there are several, probably at least two with JSONObject.) Commented Mar 1, 2017 at 9:34

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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 '\'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.