{"state":200,"message":"学生添加成功","data":{"id":null,"phone":"18832133971","username":"赵欣怡","identify":"3056"}}帮我写一个java代码来解析上面的字符串
时间: 2024-01-16 09:18:54 浏览: 70
以下是使用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);
}
}
```
阅读全文