VamsiKrishna VamsiKrishna - 1 year ago 101
Java Question

How to add a URL String in a JSON object

I need to add a URL typically in the format http:\\somepage.asp.
When I create a string with the above URL and add it to JSON object json



it's appending an extra "\" and when I check the output it's like

When I give the URL as

the json output is

Can you help me to retrieve the URL as it is, please?


Answer Source

Your JSON library automatically escapes characters like slashes. On the receiving end, you'll have to remove those backslashes by using a function like replace().

Here's an example:

string receivedUrlString = "http:\/\/\/somepage.asp";<br />
string cleanedUrlString  = receivedUrlString.replace('\', '');

cleanedUrlString should be "".

Hope this helps.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download