我正在从电视节目网站获取电视节目表,但我正在获取文字的象形文字。
这是html
<div id="tabs-1">
<div class="tab-content clear">
<div class="col">
<h2 class="col-heading">претпладне</h2>
<ul class="col-list">
<li class="col-item">
<span class="time">06:45</span>
<span class="title">
<span class="h4">Македонија наутро</span>
<br />
<span class="em">инфостудио</span>
</span>
</li>
<li class="col-item">
<span class="time">09:15</span>
<span class="title">
<span class="h4">Музичко интермецо</span>
<br />
<span class="em">•</span>
</span>
</li>
这就是jsoup返回的内容
<li class="col-item">
b <span class="time">06:45</span>
<span class="title">
<span class="h4">ÐакедониÑа наÑÑÑо</span>
<br>
<span class="em">инÑоÑÑÑдио</span>
</span>
</li>
<li class="col-item">
b <span class="time">09:15</span>
<span class="title">
<span class="h4">ÐÑзиÑко инÑеÑмеÑо</span>
<br>
<span class="em">â¢</span>
</span>
</li>
看到ÐакÐμÐ'ониÑанаÑÑÑѾ¾,这就是问题所在。 这是我的代码
Document document = Jsoup.parse(response);
Element description = document.getElementById("tabs-1");
Elements c = description.getElementsByTag("li").prepend("b");
Elements time = description.getElementsByClass("time");
Elements title = description.getElementsByClass("title");
String v = c.toString();
adress.append(v);
我正在使用Volley库,这就是为什么我要解析响应字符串,不要混淆。这是我试图解析http://creativa5.com/dev/mtvepg/programa/的网址。
我尝试使用
Document document = Jsoup.parse(response, "ISO-8859-1");
但同样的事情。
如何将此编码为utf-8?
答案 0 :(得分:0)
public class JsonObjectRequestGet extends Request {
@Override
protected Response parseNetworkResponse(NetworkResponse response) {
try {
//here to utf-8
String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
return Response.success(new JSONObject(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
}
答案 1 :(得分:0)
这是我的请求方法
private StringRequest mtvPrograma() {
StringRequest stringRequest = new StringRequest(Request.Method.GET, "http://creativa5.com/dev/mtvepg/programa/",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Document document = Jsoup.parse(response,"utf-8");
Element description = document.getElementById("tabs-1");
Elements c = description.getElementsByTag("li").prepend("b");
Elements time = description.getElementsByClass("time");
Elements title = description.getElementsByClass("title");
String v = c.text().replaceAll("b", "\n\n");;
adress.append(v);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
return stringRequest;
}