Dispatcher not handling character encoding for the json | Community
Skip to main content
Level 2
October 16, 2015
Solved

Dispatcher not handling character encoding for the json

  • October 16, 2015
  • 1 reply
  • 1590 views

We have multilingual site where in we get a JSON with both english and Chinese values [keys are in english and values in chinese], we want to cache this json on dispatcher and when we do so it looses its encoding information.

Source Sample JSON [not complete JSON but first few lines on it] -

{ "province": [{ "name": "上海", "type": "province", "children": [{ "name": "上海市", "type": "city", "children": [{ "name": "长宁区", "type": "district", "children": [{ "name": "200112", "type": "zip" },{ "name": "200123", "type": "zip" },{ "name": "200050", "type": "zip" },{ "name": "200051", "type": "zip" },{ "name": "200052", "type": "zip" },{ "name": "200335", "type": "zip" },{ "name": "200336", "type": "zip" } ] },{ "name": "闸北", "type": "district", "children": [{ "name": "200090", "type": "zip" } ] },{ "name": "黄浦区", "type": "district", "children": [{ "name": "200001", "type": "zip" },{ "name": "200003", "type": "zip" },{ "name": "200010", "type": "zip" },{ "name": "200011", "type": "zip" },{ "name": "200020", "type": "zip" },{ "name": "200021", "type": "zip" },{ "name": "200023", "type": "zip" },{ "name": "200025", "type": "zip" } ] }

 

Cached JSON [first few lines] -

province": [{ "name": "上海", "type": "province", "children": [{ "name": "上海市", "type": "city", "children": [{ "name": "长宁区", "type": "district", "children": [{ "name": "200112", "type": "zip" },{ "name": "200123", "type": "zip" },{ "name": "200050", "type": "zip" },{ "name": "200051", "type": "zip" },{ "name": "200052", "type": "zip" },{ "name": "200335", "type": "zip" },{ "name": "200336", "type": "zip" } ] },{ "name": "闸北", "type": "district", "children": [{ "name": "200090", "type": "zip" } ] },{ "name": "黄浦区", "type": "district", "children": [{ "name": "200001", "type": "zip" },{ "name": "200003", "type": "zip" },{ "name": "200010", "type": "zip" },{ "name": "200011", "type": "zip" },{ "name": "200020", "type": "zip" },{ "name": "200021", "type": "zip" },{ "name": "200023", "type": "zip" },{ "name": "200025", "type": "zip" } ]

 

We have verified that the Apache's default encoding is UTF-8 and also the OS encoding is UTF-8. Is there a way to cache the JSON correctly retaining the Chinese characters as is?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Sham_HC

The Dispatcher is just a reverse proxy and a caching module. It does not process the content it receives and caches it as is.  Either charset for the json is not set to UTF-8 Or your apache encoding might not be set properly for your vhost etc...   Most of the cases I have seen misconfiguration at webserver level.  At web server for .htaccess file in the apache htdocs directory include  "AddDefaultCharset UTF-8". By doing this, it interprets all the content as utf-8.

1 reply

Sham_HC
Sham_HCAccepted solution
Level 10
October 16, 2015

The Dispatcher is just a reverse proxy and a caching module. It does not process the content it receives and caches it as is.  Either charset for the json is not set to UTF-8 Or your apache encoding might not be set properly for your vhost etc...   Most of the cases I have seen misconfiguration at webserver level.  At web server for .htaccess file in the apache htdocs directory include  "AddDefaultCharset UTF-8". By doing this, it interprets all the content as utf-8.