我有一个代码,根据其url搜索数据库并生成相关结果。 当数据库中的数据是英文时,它工作得很完美,但当我用我的语言(HINDI)替换它时,它开始生成垃圾编码。从我的方法生成的JSON响应完美地生成了所需的数据,但浏览器没有以正确的方式显示它(在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"]}]}"
请帮助我找出错误的内容..
答案 0 :(得分:2)
问题是数据的字符编码。你正在使用一个名为UTF-8的。但是你的浏览器认为你使用的是一个名为ISO-8859的浏览器,因为当你没有告诉浏览器你想要什么时,这就是HTML的标准。在java中,您可以使用HttpServletResposne对象来配置此信息。只需致电:
response.setCharacterEncoding("UTF-8");
然后浏览器将正确解释数据。这通常是通过过滤器或项目的另一个中心点来完成的,因为今天大多数项目都希望与UTF-8进行完整的沟通,以避免遇到你现在面临的问题
答案 1 :(得分:2)
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
或
@Produces({MediaType.APPLICATION_JSON +";charset=utf-8"})
我的代码中缺少这个,现在它正常工作
答案 2 :(得分:1)
在您的回复中,请尝试使用内容编码UTF-8 。
我尝试使用记事本复制问题中的文本并将其保存在文本文件中。它在我使用UTF-8编码时起作用。
我甚至尝试将此文本与使用Visual Studio 2010 SP1的MVC4项目一起使用。
希望这有帮助!
的Vivek