Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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..

like image 750
Maddy Avatar asked Mar 29 '13 10:03

Maddy


2 Answers

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

like image 113
Bernd Ebertz Avatar answered Sep 29 '22 09:09

Bernd Ebertz


@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

like image 34
Maddy Avatar answered Sep 29 '22 09:09

Maddy