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