2

My required JSON is :

[    "URI" : "http://192.168.1.1/"    ]

I use the following way to create this JSON:

{    
    String requiredUri = "http://192.168.1.1/";
    JSOnObject jsonObject = new JSONObject();
    jsonObject.put("URI", requiredUri);
    String jsonData = jsonObject.toString();
}

This time I get get the output as :

[
    "URI" : "http:\/\/192.168.1.1\/"
]

Please tell me what should be done so that these forward slashes are not included in the resultant json.

Prateek
  • 139
  • 1
  • 11
  • 2
    You should look here: [JSON: why are forward slashes escaped?](http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped). – Simon Dorociak Jan 19 '15 at 09:31
  • Thanks Rangar, I just looked into the reference you provided. I get the thing that forward slashes are placed automatically, I needed to know if there is anyway through which these forward slashes are not allowed to occur in the Json and i get the required Json – Prateek Jan 19 '15 at 09:35
  • Ragnar gave you the correct information on why this is happening in his comment. He linked to: http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped To solve this problem you can parse and stringify the string to get rid of the extra backslashes. Example: JSON.stringify(JSON.parse('{"test":"\/hello\/world"}')); – Flipbed Jan 19 '15 at 09:46
  • Thanks Flipbed, But the problem is , stringify works in Javascript whereas, I am using Java to do this.... there isn't anything as stringify in Java – Prateek Jan 19 '15 at 09:52

0 Answers0