字符串操作
1.换行符
private static final String LINE_SEPRATOR = System.lineSeparator();
2.生成带换行的字符串
StringBuffer buffer = new StringBuffer(); for(String dataString : data) { buffer.append(dataString + LINE_SEPRATOR); }
3.按行读取字符串
try (StringReader sr = new StringReader(result); BufferedReader br = new BufferedReader(sr)) { while ((line = br.readLine()) != null) { System.out.println("解析数据:" + "\"" + line + "\""); RateLog log = JSONObject.parseObject(line, RateLog.class); System.out.println(log.getGatherTime() + ":" + log.getSn()); } } catch (IOException e) { e.printStackTrace(); return; }