Encoding problem

danvica

Member
Licensed User
Longtime User
Sorry, I red this has been already discussed but I'm still stuck.

I need to retreive from a mysql database some strings that contain characters like "ç", "ñ" and so on.

I read them using a PHP script and the

Response.GetString("UTF-8")

function where Response is a HttpResponse.

I tried to encode the mysql field using several UTF-8 variations but all of them return a truncated string where the irrugual char is.

I.E. "Française" becomes "Fran"

Any idea ? Could the problem be into the PHP script ? I use json_encode that uses Unicode only and converts those character into \uxxx format.
I tried to decode the string using:

Response.GetString("ISO-8859-1")

That should be the Unicode regulamentation but the result is the same.

Any idea ?
 

danvica

Member
Licensed User
Longtime User
I think the problem is in the PHP Json_encode function.
The string I receive back from it is complete as Json format. It just truncates the voices into the {...} closures.

This is the log:

Response CFG from server: [{"ID":"5","Name":"Deutsch","Class":"0"},{"ID":"1","Name":"English","Class":"0"},{"ID":"4","Name":"Espa","Class":"0"},{"ID":"3","Name":"Fran","Class":"0"},{"ID":"2","Name":"Italiano","Class":"0"}]

Do you agree ?
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
The following code...

B4X:
<?php
     
     $array = array("Française" => 1, "Piñata" => 2);    

     echo json_encode($array);

?>

...will print something like:

B4X:
{"Fran\u00e7aise":1,"Pi\u00f1ata":2}

JSON uses UTF8

Not sure how B4A will decode it, I haven't tried that.
 
Upvote 0

danvica

Member
Licensed User
Longtime User
I had found that Json_encode works with Unicode only but here it seems as you say... PHP: json_encode - Manual

I'll try that:

json_encode(utf8_encode($Content));

The resulting string should be coded as the input one.

I'll let you know.
 
Upvote 0

danvica

Member
Licensed User
Longtime User
Yes, the problem was in the PHP script. It's a little OF but... just in case, I added this line:

mysql_query("SET NAMES 'utf8'");

to the script.

The JSON result is as you wrote and B4A decodes it in the right way.
 
Upvote 0
Top