由Google Maps Query返回的JSON包含编码字符,如\x26(如何解码?) [英] JSON returned by Google Maps Query contains encoded characters like \x26 (how to decode?)
问题描述
在一个Java应用程序中,我得到了JSON(来自Google Maps),其中包含字符如 \x26
,我想将它转换为原始字符 &安培;
。据我所知,这是一个UTF-8符号,但我不完全确定。在源JSON中,可以出现各种编码字符(例如 \ x3c / div\x3e
)。如何解码它们?
我试过了:
字符串json =\\x3c / div\\x3e;
byte [] b = json.getBytes(UTF-8);
json = new String(b,UTF-8);
没有运气。任何想法?
> 字符串json =\\x3c / div\\x3e;
json = URLDecoder.decode(\\,%) )
.replace(\\&,=)
.replace(\\?,=);
Google地图查询JSON结果导致的其他问题需要另外三个替换。
In a Java app, i get JSON (from Google Maps) with characters like \x26
which i want to convert to its original character &
. As far as i can see, that's a UTF-8 notation, but i am not completely sure. In the source JSON all kinds of encoded characters can appear (e.g. \x3c/div\x3e
). How can i decode them?
I tried:
String json = "\\x3c/div\\x3e";
byte [] b = json.getBytes("UTF-8");
json = new String(b,"UTF-8");
No luck. Any ideas?
Got it to work:
String json = "\\x3c/div\\x3e";
json = URLDecoder.decode(json.replace("\\x", "%"), "UTF-8")
.replace("\\=", "=")
.replace("\\&", "=")
.replace("\\?", "=");
The three other replaces are needed for other problems that occur with the result of a Google Maps Query JSON Result.
这篇关于由Google Maps Query返回的JSON包含编码字符,如\x26(如何解码?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!