{"state":200,"message":"学生添加成功","data":{"id":null,"phone":"18832133971","username":"赵欣怡","identify":"3056"}}帮我写一个java代码来解析上面的字符串
时间: 2024-01-16 12:18:54 浏览: 30
以下是使用Java解析给定字符串的代码示例:
```java
import org.json.JSONObject;
public class JsonParser {
public static void main(String[] args) {
String jsonString = "{\"state\":200,\"message\":\"学生添加成功\",\"data\":{\"id\":null,\"phone\":\"18832133971\",\"username\":\"赵欣怡\",\"identify\":\"3056\"}}";
JSONObject jsonObject = new JSONObject(jsonString);
int state = jsonObject.getInt("state");
String message = jsonObject.getString("message");
JSONObject data = jsonObject.getJSONObject("data");
String phone = data.getString("phone");
String username = data.getString("username");
String identify = data.getString("identify");
System.out.println("State: " + state);
System.out.println("Message: " + message);
System.out.println("Phone: " + phone);
System.out.println("Username: " + username);
System.out.println("Identify: " + identify);
}
}
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![dll](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![mp4](https://img-home.csdnimg.cn/images/20210720083504.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)