上上篇文章:小米手机取得root权限并装置EdXposed框架(附下载链接)
上一篇文章:应用fiddler爬取app的https包(附下载链接+图解)
上一篇文章咱们曾经拿到json包了,咱们可能须要将它外面的一些信息整理出来,因为并不是所有的信息咱们都是须要的,这里咱们采纳Java的环境进行对json包的解析。
-
筹备工作
- 应用工具:IntelliJ IDEA
-
导入两个依赖:第一个是org.json包,另一个是XSSF。
- org.json包是一个用来beans,collections,maps,java arrays,XML和JSON相互转换的包,次要提供JSONObject和JSONArray类,是Java罕用的Json解析工具。
- XSSF - 提供读写Microsoft Excel OOXML XLSX格局档案的性能。
- 导入json包,并且转换成我的项目。
- 取得须要的货色
- 导出到excel表中
1、依赖的代码
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20200518</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10.1</version>
</dependency>
2、导入的代码
public class daolu {
public static void main(String[] args) throws IOException {
System.out.println(readTxtFileIntoStringArrList("须要转换文件的地址"));
List<String> a = readTxtFileIntoStringArrList("须要转换文件的地址");
char b = '\n';
String c = listToString3(a, b);
//System.out.println(c);
}
public static List<String> readTxtFileIntoStringArrList(String filePath) {
List<String> list = new ArrayList<String>();
try {
String encoding = "UTF-8";
File file = new File(filePath);
if (file.isFile() && file.exists()) {
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null) {
list.add(lineTxt);
}
bufferedReader.close();
read.close();
} else {
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
return list;
}
public static String listToString3(List list, char separator) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
sb.append(list.get(i));
if (i < list.size() - 1) {
sb.append(separator);
}
}
return sb.toString();
}
}
3、依据本人要求抉择要什么数据(可依据这个来查看json文件的构造)
public class day13 {
public static void main(String[] args) throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("13");
System.out.println(readTxtFileIntoStringArrList("C:\\Users\\xft32\\Desktop\\13.txt"));
List<String> a = readTxtFileIntoStringArrList("C:\\Users\\xft32\\Desktop\\13.txt");
char b = '\n';
String c = listToString3(a, b);
JSONObject myJSONObject;
try {
myJSONObject = new JSONObject(c);
JSONObject storeInfo = myJSONObject.getJSONObject("storeInfo");
JSONArray activities = storeInfo.getJSONArray("activities");
for (int j = 0; j < activities.length(); j++) {
JSONObject q = activities.getJSONObject(j);
String description = q.getString("description");
String icon_name = q.getString("icon_name");
System.out.println("description=" + description);
System.out.println("icon_name=" + icon_name);
String name = null;
if (q.isNull("name")) {
} else {
name = q.getString("name");
System.out.println("name=" + name);
}
XSSFRow row = sheet.createRow(j);
row.createCell(0).setCellValue("description=" + description);
row.createCell(1).setCellValue("icon_name=" + icon_name);
row.createCell(2).setCellValue("name=" + name);
}
} catch (JSONException e) {
e.printStackTrace();
System.out.println("异样");
}
FileOutputStream out = new FileOutputStream("C:\\Users\\xft32\\Desktop\\13.xlsx");
workbook.write(out);
out.flush();
out.close();
System.out.println("写入胜利");
}
4、导出到excel表
public class day14 {
public static void main(String[] args) throws IOException {
XSSFWorkbook workbook =new XSSFWorkbook();//创立新的excel表
XSSFSheet sheet =workbook.createSheet("13");//工作表标签命名
XSSFRow row=sheet.createRow(0);//第几行
row.createCell(0).setCellValue("");//第几个格子,内容是什么
FileOutputStream out=new FileOutputStream("C:\\Users\\xft32\\Desktop\\13.xlsx");/输入地位和名字命名
workbook.write(out);
out.flush();
out.close();
System.out.println("写入胜利");
}
}
利用这个办法咱们能够更无效的实现数据的收集。
发表回复