Expand my Community achievements bar.

SOLVED

Dispatcher not handling character encoding for the json

Avatar

Level 2

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?

1 Accepted Solution

Avatar

Correct answer by
Level 10

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.

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

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.