JSON字符串Gson,JSONObject解析中文乱码,接口
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json

·
mysql数据库中有一个字段类型为json,而且其中存在key=中文,而不是key=“中文”,这种数据在对外提供接口数据的时候,发现页面返回的数据是乱码!!!!我勒个去!
Debug时发现,无论使用JSONObject还是Gson去解析从mysql中查询出来的字符串得到的结果都是乱码!
后来发现了下面这篇博客的内容后尝试后成功了!
1.比如接口传参数为中文会乱码
接口中传过来key=中文;;;;而不是这种类型的“中文”,会乱码报错什么的,解决方法
byte[] temp=key.getBytes("iso8859-1");
key = new String(temp);
以下是我的处理方式,成功解析!
JSONArray json1= JSONObject.parseArray(new String(result.getList().getBytes("iso8859-1"), "UTF-8"));
List json2 = gson.fromJson(new String(result.getList().getBytes("iso8859-1"), "UTF-8"), List.class);
System.out.println("json1="+ json1);
System.out.println("json2="+ json2);




适用于现代 C++ 的 JSON。
最近提交(Master分支:5 个月前 )
34665ae6
binary -> binary_t
Signed-off-by: Robert Chisholm <robert.chisholm@sheffield.ac.uk> 21 天前
f3dc4684
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.9 to 3.28.10.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0...b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d)
---
updated-dependencies:
- dependency-name: github/codeql-action
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 28 天前
更多推荐
所有评论(0)