1

When I encode an array to JSON I get "u00e1" instead of á.

How could I solve the character encoding?

Thanks

2
  • How do you encode your array and how do you process that encoded array? Commented Mar 12, 2010 at 18:50
  • You might want to add which language (PHP/Python/ASP/...) you're using and where your input is coming from (database/HTTP-submitted form/...) Commented Mar 12, 2010 at 19:36

4 Answers 4

4

Your input data is not Unicode. 0xE1 is legacy latin1/ISO-8859-*/Windows-1252 for á. \u00e1 is the JSON/JavaScript to encode that. JSON must use a Unicode encoding.

Solve it by either fixing your input or converting it using something like iconv.

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

Comments

1

The browser's default encoding is probably Unicode UTF-8. Try <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">.

Comments

0

One problem can be if you check the response only (the response is only a text but the JSON must be an object).

You have to parse the response text to be a javascript object first (JSON.parse in javascript) and after that the characters will become the same as on the server side.

Example: On the server in the php code:

$myString = "árvízrtűrő tükörfúrógép";
echo json_encode($myString); //this sends the encoded string via a protocol that maybe    can handle only ascii characters, so the result on the client side is:

On the client side

alert(response); //check the text sent by the php

output: "\u00e1rv\u00edzrt\u0171r\u0151 t\u00fck\u00f6rf\u00far\u00f3g\u00e9p"

Make a js object from the respopnse

parsedResponse = JSON.parse(response);
alert(parsedResponse);

output: "árvízrtűrő tükörfúrógép"

Comments

0

add this to the head of html to solve this.

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

Comments

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.