使用百度API store中的身份证查询API查询返回JSON格式的数据.
String jsonResult={"errNum":-1,"retMsg":"\u8eab\u4efd\u8bc1\u53f7\u7801\u4e0d\u5408\u6cd5!","retData":[]}
我使用GSON
Gson gson=new Gson();
JsonParser parser = new JsonParser();
JsonElement el = parser.parse(jsonResult);
String aString=gson.toJson(jsonResult);
System.out.println(aString);
打印出来为:
{"errNum":-1,"retMsg":"\u8eab\u4efd\u8bc1\u53f7\u7801\u4e0d\u5408\u6cd5!","retData":[]}rn"
有什么简单的方法。将unicode的json转化为中文?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
输出:身份证号码不合法!
建议用ali的fastjson会默认转换unicode为utf-8
输出:{"errNum":-1,"retMsg":"身份证号码不合法!","retData":[]}
Gson会把html标签,转换为Unicode转义字符
正确方法:
根本就不用管好吧,自动会转成中文
我也遇到过,还是
URLDecoder.decode()、和其他办法,可是不管用。也不知道是哪里出问题,也许是开始不应该把 jsonResult 当成字符串吧。最后自己写了个方法来转换字符串。