我在我的应用程序中使用JSON类。但是,我遇到了阿拉伯语alphbet的问题。每当我尝试写入我的数据库时,我都会得到??????为阿拉伯语。对于英语来说没问题。我在我的php中setchar与utf-8兼容,并且在数据库中,字段是utf-general-ci。但是,我认为问题在于我的JSON类。这是我的JSON类。
public class JSONParser {
public JSONObject makeHttpRequest(String url, List<NameValuePair> pairs)
{
try
{
HttpParams httpParams = new BasicHttpParams();
int timeoutConnection = 10000;
HttpConnectionParams.setConnectionTimeout(httpParams, timeoutConnection);
int timeoutSocket = 10000;
HttpConnectionParams.setConnectionTimeout(httpParams, timeoutSocket);
DefaultHttpClient defaultHttpClient = new DefaultHttpClient(httpParams);
HttpPost httpPost = new HttpPost(url);
if (pairs != null)
{
httpPost.setEntity(new UrlEncodedFormEntity(pairs) );
}
HttpResponse httpResponse = defaultHttpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null)
{
String ret = EntityUtils.toString(httpEntity);
return new JSONObject(ret.substring(ret.indexOf("{"), ret.lastIndexOf("}") + 1));
}
}
catch (Exception ex)
{
}
return null;
}
}
我相信它正在使用默认加密。如何将其修复为UTF-8。好吧,在我使用http.Post.setEntity的行中,我试图将“UTF-8”作为方法setEntity中的另一个参数。它给了我一个错误。那么,你有什么建议????在此先感谢
答案 0 :(得分:1)
尝试替换
String ret = EntityUtils.toString(httpEntity);
这一行
String ret = EntityUtils.toString(entity, HTTP.UTF_8);
也许它不是json而是HttpClient