I have a client / server app written using Android and I'm using the standard org.json package classes bundled with android to do the parsing and creating.
I've been getting weird characters appearing on the server side right in the middle of the json strings generated for example (not the full one, because its big):
{!lo":"es_MX","id":2791884,"os":"8"}
As you can see the (!) exclamation mark appears randomly instead of a double quote. I also get other random characters appearing mid string. It's very bizarre.
Here is the code which creates the JSON object...
JSONObject jsonObject = new JSONObject();
jsonObject.put("key", someValue);
Here is the code which sends..
HttpPost type = new HttpPost(<server url here>);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("v", jsonObject.toString()));
type.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
httpClient.execute(type); // This is a DefaultHttpClient
I say random, but the exclamation mark in this exact position is consistent in many errors, but not every-time. About 5 messages that get this error, among tens of thousands per day. And usually not the contents of the values inserted into the json, but the characters (such as the quote character above) that define the structure of the message, which suggests to me that this isn't a character set issue.
Has anyone come across this?
It looks like your sender is not properly setting the character set. Spanish will have symbols not present in regular ASCII or most Windows encodings, you need to use UTF-8:
Content-Type: text/html; charset=utf-8
Without knowing which HTTP exchange you're using (read more), it is not possible to give you an exact code snippet to fix the problem - but that should be easy enough to figure out.