【发布时间】:2014-04-28 00:26:47
【问题描述】:
我对变音符号有疑问。
当我尝试在我的网络上手动添加用户时,所有内容都完美保存在数据库中(还有 ě、š、č、ř、ž、ý、á、í、é 等字符),但是当我保存字符串时
String diacritic = "ěščřřžžýáíé";
并将它传递给 NameValuePair 参数中的 getJSONFromUrl,它会保存到数据库中,如下所示:
?????
我真的不知道如何让它工作
public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {
// Making HTTP request
try {
HttpParams arg = new BasicHttpParams();
HttpProtocolParams.setVersion(arg, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(arg, "utf-8");
// defaultHttpClient
HttpClient httpClient = new DefaultHttpClient(arg);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String jsonText = EntityUtils.toString(httpEntity, HTTP.UTF_8);
try {
jObj = new JSONObject(jsonText);
} catch (JSONException e) {
Log.w("JSON Parser", "Error parsing data " + e.toString());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return jObj;
}
像这样保存:
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", "fb_register"));
params.add(new BasicNameValuePair("diacritic", "ěščřžýáíé"));
JSONObject json = jsonParser.getJSONFromUrl(URL, params);
也试过
Charset.forName("UTF-8").encode(diacritic);
params.add(new BasicNameValuePair("diacritic", diacritic));
【问题讨论】:
-
你的数据库编码是 utf-8 吗?
-
数据库、表、列...全部utf8_bin
标签: android json http-request