deleted0create_time2023-08-14 165623manName吴德伦x1299oidID3616599202002090manId3616599202002090y12_id3741954343595363time2023-08-14 165623addr2#楼2F0018userId1501BBdeleted0create_time2023-08-14 165523man
您可以使用JSON库(如JSON-Java或Gson)将字符串转换为List
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
String jsonString = "[{\"deleted\":0,\"create_time\":\"2023-08-14 16:56:23\",\"manName\":\"吴德伦\",\"x\":12.99,\"oidID\":[3616599202002090],\"manId\":3616599202002090,\"y\":12,\"_id\":3741954343595363,\"time\":\"2023-08-14 16:56:23\",\"addr\":\"2#楼2F0018\",\"userId\":\"1501BB\"},{\"deleted\":0,\"create_time\":\"2023-08-14 16:55:23\",\"manName\":\"吴德伦\",\"x\":11.144,\"oidID\":[3616599202002090],\"manId\":3616599202002090,\"y\":10.2,\"_id\":3741952377810275,\"time\":\"2023-08-14 16:55:23\",\"addr\":\"2#楼1F0003\",\"userId\":\"1501BB\"},{\"deleted\":0,\"create_time\":\"2023-08-14 16:54:23\",\"manName\":\"吴德伦\",\"x\":12.99,\"oidID\":[3616599202002090],\"manId\":3616599202002090,\"y\":12,\"_id\":3741950411140452,\"time\":\"2023-08-14 16:54:23\",\"addr\":\"2#楼2F0018\",\"userId\":\"1501BB\"},{\"deleted\":0,\"create_time\":\"2023-08-14 16:53:23\",\"manName\":\"吴德伦\",\"x\":12.797,\"oidID\":[3616599202002090],\"manId\":3616599202002090,\"y\":8.5,\"_id\":3741948444765565,\"time\":\"2023-08-14 16:53:23\",\"addr\":\"2#楼2F0002\",\"userId\":\"1501BB\"},{\"deleted\":0,\"create_time\":\"2023-08-14 16:52:23\",\"manName\":\"吴德伦\",\"x\":12.797,\"oidID\":[3616599202002090],\"manId\":3616599202002090,\"y\":8.5,\"_id\":3741946478816611,\"time\":\"2023-08-14 16:52:23\",\"addr\":\"2#楼2F0002\",\"userId\":\"1501BB\"},{\"deleted\":0,\"create_time\":\"2023-08-14 16:51:23\",\"manName\":\"吴德伦\",\"x\":12.797,\"oidID\":[3616599202002090],\"manId\":3616599202002090,\"y\":8.5,\"_id\":3741944512408782,\"time\":\"2023-08-14 16:51:23\",\"addr\":\"2#楼2F0002\",\"userId\":\"1501BB\"},{\"deleted\":0,\"create_time\":\"2023-08-14 16:50:23\",\"manName\":\"吴德伦\",\"x\":12.797,\"oidID\":[3616599202002090],\"manId\":3616599202002090,\"y\":8.5,\"_id\":3741942546197860,\"time\":\"2023-08-14 16:50:23\",\"addr\":\"2#楼2F0002\",\"userId\":\"1501BB\"},{\"deleted\":0,\"create_time\":\"2023-08-14 16:49:23\",\"manName\":\"吴德伦\",\"x\":12.797,\"oidID\":[3616599202002090],\"manId\":3616599202002090,\"y\":8.5,\"_id\":3741940550069453,\"time\":\"2023-08-14 16:49:23\",\"addr\":\"2#楼1F0002\",\"userId\":\"1501BB\"}]";
List<JSONObject> jsonList = new ArrayList<>();
JSONArray jsonArray = new JSONArray(jsonString);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
jsonList.add(jsonObject);
}
// 打印转换后的List<JSONObject>
for (JSONObject jsonObject : jsonList) {
System.out.println(jsonObject);
}
}
}
请注意,您需要在项目中添加JSON-Java库的依赖。以上代码将字符串转换为一个包含多个JSONObject的List,并遍历打印每个JSONObject的内容
原文地址: http://www.cveoy.top/t/topic/iDlw 著作权归作者所有。请勿转载和采集!