[英]Java String.valueOf(jsonArray) turns UTF-8 encoded content from jsonArray into question marks
I have this json array (of type JSONArray) containing utf-8 encoded strings:我有这个包含 utf-8 编码字符串的 json 数组(JSONArray 类型):
[{
"success":true,
"data":[
{"moduleTitle":"تست",
"title":"تست دو"}
],
"status":200
}]
And then I would like to get the string value of it.然后我想得到它的字符串值。
String s = String.valueOf(jsonArray);
but the utf-8 strings will be turned into question marks like this:但是 utf-8 字符串将变成这样的问号:
"[{ "success":true, "data":[ {"moduleTitle":"???", "title":"???
"[{ "成功":true, "数据":[ {"moduleTitle":"???", "title":"??? ??"} ], "status":200 }]"
??"} ], "状态":200 }]"
how can I make it show the strings correctly?我怎样才能让它正确显示字符串?
You are converting the data using the JVM's default charset, UTF-8 charset most probably is not on your server or local.您正在使用 JVM 的默认字符集转换数据,UTF-8 字符集很可能不在您的服务器或本地。
Try using this:尝试使用这个:
String s = String.valueOf(jsonArray);
String string2 = new String(s.getBytes(),"UTF-8");
return new ResponseEntity<String>(string2, HttpStatus.OK);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.