special characters between php and java android using Json encode -


As I have a site in the title, I have emphasized the character encoding problem. I have found many solutions on the web but this Does not work or I do not have to use it. In the beginning: I am collecting all the data in php myssql base and I give the json_encode function for application in the data. This is where it crashes all the fields where there is a character with accents, it is placed in an empty space. The data base is either a website (which I can not change it) and it is encoded in Windows 1252 which is inserted directly with wampPHP, why I got a solution

  $ Liste_amis = $ bdd-> Query ('select FROM lieux'); $ Nombre_amis = 0; While ($ myliste = $ liste_amis-> fetch ()) {foreach ($ myliste as & $ value) {$ value = mb_convert_encoding ($ value, "UTF-8", "Windows-1252"); } $ Output [] = array_map ('utf8_encode', $ myliste); } Print (json_encode ($ output));   

But it only works for data inserted with wampPHP and it looks like "disco" and "lock disk" like "diskath \ u00c3 \ u00183"

and The remaining readers are always using my BufferedReader in my Java code

  try {BufferedReader reader = new BufferedReader (New InputStreamReader ("UTF-8" Is), 8192); Stringbilder sb = new stringbiller (); String line = faucet; Int i = 0; While ((line = reader. Readline ()) = null (); {sb.append (line); I ++;   

Help

Edit:

Finally it works, solution: < pre> Mysql_query ("utf8" SET NAMES); // --... while ($ myliste = $ liste_amis-> fetch ()) {$ output [] = array_map ('utf8_encode', $ myliste); } Print (json_encode ($ output, JSON_UNESCAPED_UNICODE));

java:

  BufferedReader Reader = new BufferedReader (new inputstreamreader ("UTF-8"), 8);   

the tank.

Write your code again ...

  foreach ($ Myliste & amp; $ value) {$ value = mb_convert_encoding ($ value, "UTF-8", "Windows-1252"); } $ Output [] = array_map ('utf8_encode', $ myliste); } Print (json_encode ($ output, JSON_UNESCAPED_UNICODE));    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -