Reputation: 305
How do you escape the character "ü" in a string.
I have this character in my json data:
{"Name": "Hyüsin"}
when I do a HttpPost in my android to the webServer. it gives me a "Bad Request" error as response.
HttpPost Code:
// 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;
}
}
}
Upvotes: 3
Views: 1202
Reputation: 284786
Use:
StringEntity entity = new StringEntity(jsonTaakkaart.toString(), "UTF-8");
to specify that the encoding is UTF-8.
Upvotes: 4