Android UTF-8 西里尔文请求
Android UTF-8 cyrillic request
在我的应用程序中,我从服务器请求数据以在用户配置文件视图中显示它。
应用程序读取 JSON 数据,对其进行解析并粘贴到表单字段中。字符集没有问题,应用程序读取西里尔字符串。
我尝试更新个人资料时遇到问题:
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, "http://meWebSite.com/userProfile.php?act=edit"
+"&user_id="+user_id+
"&country="+country_1.getText().toString()+
"&city="+city_1.getText().toString(),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
parceEditingJsonRequest(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
在这种情况下,所有西里尔字符串看起来像??????
我打印了请求字符串并将其粘贴到浏览器 - 一切正常 - 西里尔字符串已正确提交到服务器,所以我确定问题不在服务器端。
真不知道从何说起。也许我应该为此请求指定字符集?
看看URLEncoder,即:
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, "http://meWebSite.com/userProfile.php?act=edit"
+"&user_id="+URLEncoder.encode(user_id, "UTF-8")+
"&country="+URLEncoder.encode(country_1.getText().toString(), "UTF-8")+
"&city="+URLEncoder.encode(city_1.getText().toString(), "UTF-8"),
然后,如果你需要,在服务器端,如果你使用php,你可以使用utf8_encode or utf8_decode。
在我的应用程序中,我从服务器请求数据以在用户配置文件视图中显示它。 应用程序读取 JSON 数据,对其进行解析并粘贴到表单字段中。字符集没有问题,应用程序读取西里尔字符串。
我尝试更新个人资料时遇到问题:
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, "http://meWebSite.com/userProfile.php?act=edit"
+"&user_id="+user_id+
"&country="+country_1.getText().toString()+
"&city="+city_1.getText().toString(),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
parceEditingJsonRequest(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
在这种情况下,所有西里尔字符串看起来像??????
我打印了请求字符串并将其粘贴到浏览器 - 一切正常 - 西里尔字符串已正确提交到服务器,所以我确定问题不在服务器端。
真不知道从何说起。也许我应该为此请求指定字符集?
看看URLEncoder,即:
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, "http://meWebSite.com/userProfile.php?act=edit"
+"&user_id="+URLEncoder.encode(user_id, "UTF-8")+
"&country="+URLEncoder.encode(country_1.getText().toString(), "UTF-8")+
"&city="+URLEncoder.encode(city_1.getText().toString(), "UTF-8"),
然后,如果你需要,在服务器端,如果你使用php,你可以使用utf8_encode or utf8_decode。