gpt4 book ai didi

java - 想要使用 RESTful Web 服务通过 JSON 响应其他语言字体(印地语)

转载 作者:搜寻专家 更新时间:2023-10-31 20:03:54 25 4
gpt4 key购买 nike

我有一个代码,可以根据其 url 搜索数据库并生成相关结果。当数据库中的数据是英文时它工作得很好但是当我用我的语言(印地语)替换它时它开始产生垃圾编码。从我的方法生成的 JSON 响应完美地生成了所需的数据,但浏览器没有以正确的方式显示它(印地语)....

**`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"]}]}"

请帮我找出问题所在..

最佳答案

问题出在您的数据的字符编码上。您正在使用一种称为 UTF-8 的编码。但是您的浏览器认为您使用的是 ISO-8859,因为当您不告诉浏览器您想要什么时,这是 HTML 的标准。在 java 中,您可以使用 HttpServletResposne 对象来配置此信息。只需调用:

response.setCharacterEncoding("UTF-8");

然后浏览器将正确解释数据。这通常是通过过滤器或项目的另一个中心点来完成的,因为今天大多数项目都希望使用 UTF-8 进行完整的通信,以避免遇到你现在面临的问题

关于java - 想要使用 RESTful Web 服务通过 JSON 响应其他语言字体(印地语),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15701340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com