["\u535a\u58eb","\u7855\u58eb","\u672c\u79d1","\u5927\u4e13","\u5927\u4e13\u4ee5\u4e0b"]将这样的json转为utf-8,在Java中
时间: 2024-06-07 08:04:46 浏览: 10
在 Java 中,可以使用 JSONObject 类来解析 JSON 数据,并将其转换为 UTF-8 编码。具体步骤如下:
1. 导入相关包
```java
import org.json.JSONObject;
```
2. 将 JSON 字符串转换为 JSONObject 对象
```java
String jsonStr = "{\"博士\": \"Doctor\", \"硕士\": \"Master\", \"本科\": \"Undergraduate\", \"大专\": \"Junior College\", \"大专以下\": \"Below Junior College\"}";
JSONObject jsonObj = new JSONObject(jsonStr);
```
3. 获取需要的值
```java
String doctor = jsonObj.getString("博士");
String master = jsonObj.getString("硕士");
String undergraduate = jsonObj.getString("本科");
String juniorCollege = jsonObj.getString("大专");
String belowJuniorCollege = jsonObj.getString("大专以下");
```
4. 将获取到的值转换为 UTF-8 编码
```java
doctor = new String(doctor.getBytes("ISO-8859-1"), "UTF-8");
master = new String(master.getBytes("ISO-8859-1"), "UTF-8");
undergraduate = new String(undergraduate.getBytes("ISO-8859-1"), "UTF-8");
juniorCollege = new String(juniorCollege.getBytes("ISO-8859-1"), "UTF-8");
belowJuniorCollege = new String(belowJuniorCollege.getBytes("ISO-8859-1"), "UTF-8");
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![html](https://img-home.csdnimg.cn/images/20210720083451.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)