0

i have a problem with json_encode with php, i use php 5.2.6 and i receive from server this data:

Array (… => Array ( [codIdenVerb] => 276122 [codAppe] => 778033 [codCorsoStud] => 00688 [descrizione] => PSICOLOGIA SOCIALE [crediti] => 9.0 [canale] => NESSUNA CANALIZZAZIONE [docente] => TONI ALESSANDRO [facolta] => SCIENZE POLITICHE, SOCIOLOGIA, COMUNICAZIONE [annoAcca] => 2012 [dataAppe] => 25/09/2012 .........

...

[note] => La prova scritta si svolgerà il giorno 10 settembre presso l'aula Magna a partire dalle ore 10.oo. La prova orale si svolgerà il giorno 25 settembre presso l'aula B14 a partire dalle ore 9.30. Si ricorda, inoltre, che la prenotazione su INFOSTUD per la data della prova ora è valida e necessaria per sostenere la prova scritta. 

..

[dataInizioPrenotazione] => 06/05/2012 [dataFinePrenotazione] => 30/08/2012 [questionario] => false [SiglaModuloDidattico] => 1010544 ) [7] => Array…)

for encode i use $json_string = json_encode($data);

but the part with [note] is cut whit: "note":"La prova scritta si svolger","..."
where is the problem? how can solve? Thanks!

1 Answer 1

2

json_encode() expects incoming data to be UTF-8.

The data you are passing to it is probably not UTF-8.

Find out what encoding it is in, and adjust the input encoding or use e.g. iconv() to convert the data from your original encoding to UTF-8.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi tnks for response but i have try this: $text = "This is the Euro symbol '€'."; echo 'Original : ', $text, PHP_EOL; echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL; echo 'IGNORE : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL; echo 'Plain : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL; but i see this: Original : This is the Euro symbol '‰âÂ'. TRANSLIT : This is the Euro symbol ' IGNORE : This is the Euro symbol ''. Plain : This is the Euro symbol ' why?
@user you mean the other way round, no? UTF-8 would have to be your target character set
yes you have right, i have try this: $string=iconv('ISO-8859-1//TRANSLIT//IGNORE','UTF-8', "sàs"); $json_string = json_encode($string); print_r($json_string); but i see "s\u00c3\u00a0s" and how can see sàa? thanks for your time and patience i'm new on php.
@user s\u00c3\u00a0s is actually correct, it's JSON's way of encoding non-ASCII characters. When you parse the JSON using a proper parser (like jQuery's .getJSON() or whatever you use to fetch it), you will see the characters look okay again.
ok thanks! I have solved with your help! thank you very much indeed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.