无法解析 JSON 中的古吉拉特语文本

我开发了一个在 JBOSS-EAP 上运行的 Web 服务。我有一个 JSON,其中包含我无法解析的古吉拉特语。


在解析古吉拉特语字体时,问号会出现在输出中。我已经搜索并发现我必须将编码更改为 UTF-8 然后它才能工作。我不知道这是否是一个正确的解决方案,但无论如何我尝试了很多方法但都失败了。


//code for getting data from JSON

JSONObject obj = object.getJSONObject("data");

obj.optString("Name");


//changed web.xml

<?xml version="1.0" encoding="UTF-8"?>


//changed encoding by this

byte ptext[] = myString.getBytes();

String value = new String(ptext, "UTF-8");


jeck猫
浏览 101回答 2
2回答

千巷猫影

我使用的是spring-boot 2,我认为它与服务器无关,我们只需将字符集添加为utf-8 我就可以从Web服务获取古吉拉特语文本。样品要求:@RequestMapping(value = "/comment/locale", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,&nbsp; &nbsp; &nbsp; &nbsp; consumes = MediaType.APPLICATION_JSON_VALUE)public String addCommentInLocale(@RequestBody Map<String,String> comment) {&nbsp; &nbsp; return comment.get("guj");}卷曲请求:curl -X POST \&nbsp; http://localhost:8080/comment/locale \&nbsp; -H 'Accept-Charset: utf-8' \&nbsp; -H 'Content-Type: application/json' \&nbsp; -H 'cache-control: no-cache' \&nbsp; -d '{&nbsp; &nbsp; "guj":"દુનિયા"}'显示请求和响应的示例图像:

冉冉说

您需要进行以下更改:可能对您有所帮助添加request.setCharacterEncoding("UTF-8")打电话之前getParameter()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java