I'm experiencing a strange problem, when I send a String from PHP to Java (Android).
The whole story is rather simple: A Java application sends a keyword to a PHP script. The PHP script looks it up in a DB and sends a JSON encoded array (as a string) back to the Java application.
I can see this string in a TextView field in Android and it looks like this: [{"name":"Berlin"}]
But Java does not accept this as a valid JSON string (unlike some online JSON validators), because it keeps throwing the exception: "A JSONArray text must start with '[' at character 1". When I compare this strings to an identical string hardcoded in Java using "equal()" it turns out, they just aren't equal. And even more disturbing: Java returns the length of the JSON string as 20, not as 19.
Why could this be? There are no unusual characters like Umlauts. What could be the 20th character? I'm suspecting some encoding problem, but I'm pretty sure everything (PHP file, Java file) is UTF-8 encoded.
(Before someone asks: I can provide code, but I don't know which part could be relevant.)
String s = " Hello World ".trim();