列如:数据结构
//为虚构数据 仅参考{ "success" : TRUE,"message" : "操作成功!","code" : 200,"result" :[{ "id" : 1,"ip" : "185.20.2","username" : "admin","password" : "1","port" : 1,"subscriptionUrl" : "http://localhost:6300/k" },{ "id" : 2,"ip" : "100.0.1.2","username" : "","password" : "","port" : "","subscriptionUrl" : "http://localhost:6300/k"}],"timestamp" : 1681953777518
}
操作如下:
实体类情况下
JSON.parseObject(jsonString); 是将Json字符串转化为相应的对象
JSONArray.parseArray 的作用是将 JSON 字符串转换为 Java 对象的数组。
Student o = JSONObject.parseObject(jsonString, Student.class);
获取单个值情况下
JSONArray jsonArray = object.getJSONArray(“result”);//获取数组
for (int j = 0; j < jsonArray.size(); j++) {
String username= jsonArray.getJSONObject(j).getString(“username”);
}