I'm really struggling with encoding strings with Java and PHP.
I use Java to manage posts in Wordpress. For this I created a GUI in JavaFX and extended the REST-API to create SEO-inserts. The Worpdress-database is encoded with utf8_general_ci.
I send the data as JSON-encoded String via Post to the WP-Api. I use org.JSON. for de-/encoding in Java.
I tried to decode the json-string with php,
json_decode($request->get_param('data'), true);
but i get following error:
Malformed UTF-8 characters, possibly incorrectly encoded
So i tried to convert it with php
$s = iconv("Windows-1252", "UTF-8", $s);
It worked but characters like "ä,ö,ü,ß" etc. just appear as ü, Ã,...
Next I tried it to encode it in Java, as described here Converting Java String From/to utf-8
private String convertToUTF8(String s) {
String out = null;
try {
out = new String(s.getBytes("UTF-8"), "ISO-8859-1");
} catch (java.io.UnsupportedEncodingException e) {
return null;
}
return out;
}
But with that and without "iconv" it fails again.
What am I doing wrong and how can i solve this?
The server runs with php7.0. I use jdk1.8.0_66 for Java.
convertToUTF8doesn't "convert" to UTF-8 it "converts" from UTF-8