gpt4 book ai didi

android - 解析来自 webservices android 的 json 响应中的特殊字符

转载 作者:行者123 更新时间:2023-11-29 01:43:29 26 4
gpt4 key购买 nike

在 php webservice 的 JSON 响应中,我得到的是 ' 而不是撇号,如何在 android 中解析带有特殊字符的 JSON 响应?

已编辑

我的Http连接方法代码-

    InputStream is = null;
String response = null,value = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
catch (UnknownHostException e) {
e.printStackTrace();
}
catch (UnsupportedEncodingException e) {

e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {

e.printStackTrace();
}


try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
String line = null;
while ((line = reader.readLine()) != null) {
value=line.trim();
}
is.close();
response = URLEncoder.encode(value,"UTF-8");
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}

当应用 URLDecoder 对响应没有影响时,当尝试使用 URLEncoder 作为响应时,一些符号和额外的字符被添加为 (%20d/)。

最佳答案

使用 Html 类我们可以做到这一点:

 String example;
if (Build.VERSION.SDK_INT >= 24) {
example = Html.fromHtml(String, int) // for 24+ api
} else {
example = Html.fromHtml(String) // for older api
}

请参阅文档 https://developer.android.com/reference/android/text/Html.html

关于android - 解析来自 webservices android 的 json 响应中的特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22909553/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com