我正在使用凌空来接收来自远程api的json响应 响应中有一个Json对象,并且在其中是阿拉伯文字 看起来像这样/ u0644 / u0739 / u0648 我试图覆盖parseNetworkResponse和Handle编码UTF-8,但是没有运气
这是我的代码
String link = "http://nano-school.com/api/teacher/day_subjects";
StringRequest sr = new StringRequest(Request.Method.POST, link,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
showMessage(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//Toast method
showMessage(error.toString());
}
}) {
@Override
public Map<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json; charset=utf-8");
headers.put("token","ymE20l9vfXM1aZB815VVzzBG1gNTgEA0US01Fw5iOxAcTLQOssmJe6eu2XGqkF7IluD0lTi9a0zGZZoolcp1kPCvkswfKvJkYWsI");
return headers;
}
@Override
public byte[] getBody() {
HashMap<String, String> params2 = new HashMap<>();
params2.put("day_id", "29");
return new JSONObject(params2).toString().getBytes();
}
@Override
protected Response<String> parseNetworkResponse (NetworkResponse response) {
try {
String utf8String = new String(response.data, "UTF-8");
return Response.success(utf8String, HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
// log error
return Response.error(new ParseError(e));
}
}
};
RequestHandler.getInstance(getApplicationContext()).addToRequestQueue(sr);