如何转义字符串中的字符“ü”。
我的 json 数据中有这个字符:
{"Name": "Hyüsin"}
当我在我的 android 中向 webServer 执行 HttpPost 时。它给了我一个“错误请求”错误作为响应。
HttpPost 代码:
// uploads the data
public class UploadData extends AsyncTask<String, Integer, Boolean> {
@Override
protected Boolean doInBackground(String... url) {
try {
HttpPost request = new HttpPost(LogInActivity.SERVICE_URI + url[0]);
request.setHeader("Content-type", "application/json; charset=utf-8");
//THIS IS {"Name": "Hyüsin"}
JSONObject jsonTaakkaart = taakkaart.serializeToObj();
StringEntity entity = new StringEntity(jsonTaakkaart .toString());
request.setEntity(entity);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}