简体   繁体   English

如何在Java中使用转义的“ \\”从json数据中提取url

[英]How can I extract url from json data with escaped “\” in java

I need to extract url from json filed. 我需要从json字段中提取网址。 (replace it with "" and do not break the json format), so that there's no url in json. (将其替换为“”,并且不要破坏json格式),以便json中没有url。

the url looks in this way 网址看起来是这样的

"source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\",
"profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/3475536942\/2b0ccd9e42754adf7e22947037dd8c34_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/488849893\/1364691799",

... ...

I noticed that there's "\\" in the url to escape the string, I don't know how to deal with it while writing the regex. 我注意到URL中有“ \\”来转义字符串,我不知道在编写正则表达式时如何处理它。

Simply use a lightweight JSON parser such as this reference implementation in Java 只需使用轻量级的JSON解析器(例如Java中的此参考实现)

To overwrite, say, the source property to "blah", it is possible to do things as simple as 要将source属性覆盖为“ blah”,可以执行以下操作:

String newJsonString = new JSONObject(originalJsonString).putString("source","blah").toString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM