Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

php - json with special characters like é

I'm developing a dependent select script using jQuery, PHP and JSON as the response.

Everything goes well except for using special characters like French ones (é , è , à...)

if I pre-encode them like (é , è , à) (Here I'm using spaces between the ampersand and the rest of the word to prevent auto encoding in my question) it works but when rendered with jquery the characters are not converted to what they should look like (é...), instead they are shown as is (é)

If I write them like (é) and don't pre-encode them the full value in this array entry is not shown.

What should I do here?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If I write them like (é) and don't pre-encode them the full value in this array entry is not shown.

What should I do here?

In JSON you do not HTML-encode values. You send them literally (é) and set set Content-Type correctly:

header('Content-Type: application/json; Charset=UTF-8');

Declare the encoding your data is in, of course.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...