Want To Have Other Language Font(Hindi) In Response Through JSON Using RESTful Web Service

戏子无情 提交于 2021-02-07 07:34:18

问题


I have a code which on the basis of its url search the database and produce related results. It was working perfect when the data in database was in english but when i replaced it with my language(HINDI) it started producing garbage encodes. The JSON response generated from my method is producing the required data perfectly but the browser is not showing it in proper way(In HINDI)....

**`Returned JSON String`** =
 "{"Emp":{"3":{"EXPERIENCE":"०","Name":"राहुल शर्मा","PROFILE":"ट्रेनी","AGE":"२५","ADDRESS":"घ्हशिअबद","ID":"103","PHONE NUMBER":"८२७३६४५५१०","array":["name","Lamis"]},"2":{"EXPERIENCE":"०","Name":"कुशल सेठ","PROFILE":"ट्रेनी","AGE":"२४","ADDRESS":"नेव देल्ही","ID":"102","PHONE NUMBER":"९१८२७३६४५०","array":["name","Lamis"]},"1":{"EXPERIENCE":"+१","Name":"अजय रण","PROFILE":"देसिग्नेर","AGE":"२७","ADDRESS":"देल्ही","ID":"101","PHONE NUMBER":"७८९९८७६५५६","array":["name","Lamis"]},"0":{"EXPERIENCE":"+१","Name":"राज सिंघ","PROFILE":"देवेलोपेर","AGE":"२६","ADDRESS":"घ्हशिअबद","ID":"100","PHONE NUMBER":"९९८८७७६६५५","array":["name","Lamis"]},"4":{"EXPERIENCE":"०","Name":"रेने रे","PROFILE":"ट्रेनी","AGE":"२३","ADDRESS":"नेव देल्ही","ID":"104","PHONE NUMBER":"८१८२८३८४८५","array":["name","Lamis"]}},"Employee Details":[{"EXPERIENCE":"+१","Name":"राज सिंघ","PROFILE":"देवेलोपेर","AGE":"२६","ADDRESS":"घ्हशिअबद","ID":"100","PHONE NUMBER":"९९८८७७६६५५","array":["name","Lamis"]},{"EXPERIENCE":"+१","Name":"अजय रण","PROFILE":"देसिग्नेर","AGE":"२७","ADDRESS":"देल्ही","ID":"101","PHONE NUMBER":"७८९९८७६५५६","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"कुशल सेठ","PROFILE":"ट्रेनी","AGE":"२४","ADDRESS":"नेव देल्ही","ID":"102","PHONE NUMBER":"९१८२७३६४५०","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"राहुल शर्मा","PROFILE":"ट्रेनी","AGE":"२५","ADDRESS":"घ्हशिअबद","ID":"103","PHONE NUMBER":"८२७३६४५५१०","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"रेने रे","PROFILE":"ट्रेनी","AGE":"२३","ADDRESS":"नेव देल्ही","ID":"104","PHONE NUMBER":"८१८२८३८४८५","array":["name","Lamis"]}],"Employee":[{"EXPERIENCE":"+१","Name":"राज सिंघ","PROFILE":"देवेलोपेर","AGE":"२६","ADDRESS":"घ्हशिअबद","ID":"100","PHONE NUMBER":"९९८८७७६६५५","array":["name","Lamis"]},{"EXPERIENCE":"+१","Name":"अजय रण","PROFILE":"देसिग्नेर","AGE":"२७","ADDRESS":"देल्ही","ID":"101","PHONE NUMBER":"७८९९८७६५५६","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"कुशल सेठ","PROFILE":"ट्रेनी","AGE":"२४","ADDRESS":"नेव देल्ही","ID":"102","PHONE NUMBER":"९१८२७३६४५०","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"राहुल शर्मा","PROFILE":"ट्रेनी","AGE":"२५","ADDRESS":"घ्हशिअबद","ID":"103","PHONE NUMBER":"८२७३६४५५१०","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"रेने रे","PROFILE":"ट्रेनी","AGE":"२३","ADDRESS":"नेव देल्ही","ID":"104","PHONE NUMBER":"८१८२८३८४८५","array":["name","Lamis"]}]}"


**And Browser Visible String** =
"{"Emp":{"3":{"EXPERIENCE":"०","Name":"राहà¥à¤² शरà¥à¤®à¤¾","PROFILE":"टà¥à¤°à¥‡à¤¨à¥€","AGE":"२५","ADDRESS":"घà¥à¤¹à¤¶à¤¿à¤…बद","ID":"103","PHONE NUMBER":"८२७३६४५५१०","array":["name","Lamis"]},"2":{"EXPERIENCE":"०","Name":"कà¥à¤¶à¤² सेठ","PROFILE":"टà¥à¤°à¥‡à¤¨à¥€","AGE":"२४","ADDRESS":"नेव देलà¥à¤¹à¥€","ID":"102","PHONE NUMBER":"९१८२७३६४५०","array":["name","Lamis"]},"1":{"EXPERIENCE":"+१","Name":"अजय रण","PROFILE":"देसिगà¥à¤¨à¥‡à¤°","AGE":"२७","ADDRESS":"देलà¥à¤¹à¥€","ID":"101","PHONE NUMBER":"७८९९८७६५५६","array":["name","Lamis"]},"0":{"EXPERIENCE":"+१","Name":"राज सिंघ","PROFILE":"देवेलोपेर","AGE":"२६","ADDRESS":"घà¥à¤¹à¤¶à¤¿à¤…बद","ID":"100","PHONE NUMBER":"९९८८७७६६५५","array":["name","Lamis"]},"4":{"EXPERIENCE":"०","Name":"रेने रे","PROFILE":"टà¥à¤°à¥‡à¤¨à¥€","AGE":"२३","ADDRESS":"नेव देलà¥à¤¹à¥€","ID":"104","PHONE NUMBER":"८१८२८३८४८५","array":["name","Lamis"]}},"Employee Details":[{"EXPERIENCE":"+१","Name":"राज सिंघ","PROFILE":"देवेलोपेर","AGE":"२६","ADDRESS":"घà¥à¤¹à¤¶à¤¿à¤…बद","ID":"100","PHONE NUMBER":"९९८८७७६६५५","array":["name","Lamis"]},{"EXPERIENCE":"+१","Name":"अजय रण","PROFILE":"देसिगà¥à¤¨à¥‡à¤°","AGE":"२७","ADDRESS":"देलà¥à¤¹à¥€","ID":"101","PHONE NUMBER":"७८९९८७६५५६","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"कà¥à¤¶à¤² सेठ","PROFILE":"टà¥à¤°à¥‡à¤¨à¥€","AGE":"२४","ADDRESS":"नेव देलà¥à¤¹à¥€","ID":"102","PHONE NUMBER":"९१८२७३६४५०","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"राहà¥à¤² शरà¥à¤®à¤¾","PROFILE":"टà¥à¤°à¥‡à¤¨à¥€","AGE":"२५","ADDRESS":"घà¥à¤¹à¤¶à¤¿à¤…बद","ID":"103","PHONE NUMBER":"८२७३६४५५१०","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"रेने रे","PROFILE":"टà¥à¤°à¥‡à¤¨à¥€","AGE":"२३","ADDRESS":"नेव देलà¥à¤¹à¥€","ID":"104","PHONE NUMBER":"८१८२८३८४८५","array":["name","Lamis"]}],"Employee":[{"EXPERIENCE":"+१","Name":"राज सिंघ","PROFILE":"देवेलोपेर","AGE":"२६","ADDRESS":"घà¥à¤¹à¤¶à¤¿à¤…बद","ID":"100","PHONE NUMBER":"९९८८७७६६५५","array":["name","Lamis"]},{"EXPERIENCE":"+१","Name":"अजय रण","PROFILE":"देसिगà¥à¤¨à¥‡à¤°","AGE":"२७","ADDRESS":"देलà¥à¤¹à¥€","ID":"101","PHONE NUMBER":"७८९९८७६५५६","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"कà¥à¤¶à¤² सेठ","PROFILE":"टà¥à¤°à¥‡à¤¨à¥€","AGE":"२४","ADDRESS":"नेव देलà¥à¤¹à¥€","ID":"102","PHONE NUMBER":"९१८२७३६४५०","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"राहà¥à¤² शरà¥à¤®à¤¾","PROFILE":"टà¥à¤°à¥‡à¤¨à¥€","AGE":"२५","ADDRESS":"घà¥à¤¹à¤¶à¤¿à¤…बद","ID":"103","PHONE NUMBER":"८२७३६४५५१०","array":["name","Lamis"]},{"EXPERIENCE":"०","Name":"रेने रे","PROFILE":"टà¥à¤°à¥‡à¤¨à¥€","AGE":"२३","ADDRESS":"नेव देलà¥à¤¹à¥€","ID":"104","PHONE NUMBER":"८१८२८३८४८५","array":["name","Lamis"]}]}"

Pls Help Me To Find Whats Wrong In This..


回答1:


The problem is the character encoding of your data. You're using one called UTF-8. But your browser thinks your using one called ISO-8859, because that's the standard for HTML when you don't tell the browser what you want. In java you can use the HttpServletResposne object to configure this information. Simply call:

response.setCharacterEncoding("UTF-8");

Then the browser will interpret the data correctly. This is often done with a filter or another central point of the project, as today most project want to do the complete communication with UTF-8, to avoid running in the problems you face now




回答2:


@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") or

@Produces({MediaType.APPLICATION_JSON +";charset=utf-8"})

This was missing in my code and now its working properly




回答3:


In your response, try using content encoding UTF-8.

I tried copying text from your question and saving it in a text file using notepad. It worked when I used UTF-8 encoding.

I have even tried using this text with an MVC4 project using Visual Studio 2010 with SP1.

Hope this helps!

Vivek



来源:https://stackoverflow.com/questions/15701340/want-to-have-other-language-fonthindi-in-response-through-json-using-restful-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!