String转对象,数组
1 String json = "{\"code\":\"200\",\"data\":{\"total\":4,\"list\":[{\"createBy\":\"admin\",\"createTime\":\"2019-09-16 10:18:47\",\"id\":2,\"params\":{},\"ruleName\":\"规则1\",\"workBegintime\":\"08:00:00\",\"workEndtime\":\"09:00:00\",\"workoffBegintime\":\"18:00:00\",\"workoffEndtime\":\"19:00:00\"},{\"createBy\":\"admin\",\"createTime\":\"2019-09-16 17:27:15\",\"id\":5,\"params\":{},\"ruleName\":\"考勤test2\",\"workBegintime\":\"07:00:00\",\"workEndtime\":\"08:20:35\",\"workoffBegintime\":\"17:20:35\",\"workoffEndtime\":\"18:20:35\"}]}}"; 2 String json2 = "[{\"第0名\":0},{\"第1名\":1},{\"第2名\":2},{\"第3名\":3},{\"第4名\":4},{\"第5名\":5},{\"第6名\":6},{\"第7名\":7},{\"第8名\":8},{\"第9名\":9}]"; 3 Map map = JSON.parseObject(json, Map.class); 4 List<Map> maps = JSON.parseArray(json2, Map.class); 5 System.out.println(map); 6 System.out.println(maps); 7 String[] arr = new String[5]; 8 arr[0] = "1"; 9 arr[1] = "2"; 10 arr[2] = "3"; 11 System.out.println(ArrayUtil.arrayToString(arr));
//代码执行结果{code=200, data={"total":4,"list":[{"createBy":"admin","workBegintime":"08:00:00","workoffEndtime":"19:00:00","createTime":"2019-09-16 10:18:47","workoffBegintime":"18:00:00","ruleName":"规则1","id":2,"params":{},"workEndtime":"09:00:00"},{"createBy":"admin","workBegintime":"07:00:00","workoffEndtime":"18:20:35","createTime":"2019-09-16 17:27:15","workoffBegintime":"17:20:35","ruleName":"考勤test2","id":5,"params":{},"workEndtime":"08:20:35"}]}} [{第0名=0}, {第1名=1}, {第2名=2}, {第3名=3}, {第4名=4}, {第5名=5}, {第6名=6}, {第7名=7}, {第8名=8}, {第9名=9}] 1 2 3
对象转String字符串
来源:https://www.cnblogs.com/mikemhm/p/11556256.html