AKSM
AKSM

Reputation: 327

— special character decoding

In our Jersey REST service, we are sending back — to the browser client, as an element in a JSON object. But the browser JQuery client which is consuming my service, instead of decoding it to a literal - is displaying it as —, the encoded value itself.

Wondering if I have to make any settings change in Jersey or JSON resolver for the client browser to understand it as a literal -. I am sending the output JSON from Jersey in UTF-16 format. Appreciate any help.

Upvotes: 0

Views: 1325

Answers (2)

Codo
Codo

Reputation: 78795

— might be valid in HTML or XML. But in JSON it's \u2014 (2014 is the hexadecimal representation of the decimal number 8212):

{
    "trip": "New York \u2014 Chicago"
}

You can check it with JSONLint.

BTW: How exactly are you generating the JSON output? You shouldn't need to take care of the details of character encoding. Jersey should do this for you.

Update: Obviously, your initial data is HTML or XML encoded (for whatever reason). So the solution is to undo the encoding before sending it as JSON. Jersey will take care of the rest.

If your data is only HTML/XML encoded for certain characters but not in general, then you have a problem that you need to fix even closer to the source.

Upvotes: 1

Tom Anderson
Tom Anderson

Reputation: 47163

Are you sending &#8212 or —? Remember an entity has to have a terminating semicolon.

Upvotes: 0

Related Questions