如何在JSON对象中添加URL字符串 [英] How to add a URL String in a JSON object

查看:681
本文介绍了如何在JSON对象中添加URL字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通常以http:\ somewebsite.com \ somepage.asp格式添加网址。
当我使用上述URL创建一个字符串并将其添加到JSON对象json

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

使用

json.put("url",urlstring);

它附加一个额外的\,当我检查输出时它就像 http:\\\\ somewebsite.com \\somepage.asp

it's appending an extra "\" and when I check the output it's like http:\\\\somewebsite.com\\somepage.asp

当我将网址设为 http://somewebsite.com/somepage.asp
json输出 http:\ / \ / somewebsite.com \ /somepage.asp

你能帮我检查一下这个URL吗?

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

谢谢

推荐答案

您的JSON库会自动转义斜杠等字符。在接收端,你必须使用像 replace()这样的函数删除那些反斜杠。

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().

这是一个例子:

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

cleaningUrlString 应为http://somewebsite.com/somepage.asp

希望这会有所帮助。

参考: http:/ /docs.oracle.com/javase/6/docs/api/java/lang/String.html#replace(char,%20char

这篇关于如何在JSON对象中添加URL字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆