获取js文件中指定的数据

来源:互联网 发布:如何升级淘宝等级 编辑:程序博客网 时间:2024/04/30 11:00
/**
* 测试提前/root/perf/admin/cqyq_apicc/perf-report下文件内容
* @param args
*/
public static void main(String[] args) {
  try {
  //得到js文件内容
BufferedReader reader = new BufferedReader(new FileReader("C:\\perf\\admin\\cqyq_apicc\\perf-report\\content\\js\\dashboard.js"));
StringBuilder sb=new StringBuilder();
String line=null;
while((line=reader.readLine())!=null){
//把换行符去掉
 sb.append(line);
}
reader.close();
int startindex=sb.indexOf("#statisticsTable");
int endindex= sb.indexOf("false}]}, function(index, item){        switch(index){ ");
System.out.println(startindex+"----------"+endindex);
//截取想要内容
String jsonString=sb.substring(startindex+20,endindex+10);
System.out.println(jsonString);
//"titles": ["Label", "#Samples", "KO", "Error %", "90th pct", "95th pct", "99th pct", "Throughput", "KB/sec", "Min", "Max"]
//转换成JSONObject对象
JSONObject js=JSONObject.fromObject(jsonString);
//获得具体属性
js.get("items");
String overallStr = js.get("overall").toString();
String titlesStr=js.get("titles").toString();
String itemsStr=js.get("items").toString();
System.out.println(overallStr);
System.out.println(titlesStr);
System.out.println(itemsStr);
} catch (IOException e) {
e.printStackTrace();
}

}



4822----------5321
{ "supportsControllersDiscrimination": true,"overall": {"data": ["Total", 447554, 447554, 100.0, 784.0, 957.0, 1244.0, 1083.6369975618084, 301.5501057894039, 2, 3789],"isController": false},"titles": ["Label", "#Samples", "KO", "Error %", "90th pct", "95th pct", "99th pct", "Throughput", "KB/sec", "Min", "Max"],"items": [{"data": ["API端查询接口", 447554, 447554, 100.0, 784.0, 957.0, 1244.0, 1083.6369975618084, 301.5501057894039, 2, 3789], "isController": false}]}
log4j:WARN File option not set for appender [myThreadfile].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
log4j:ERROR Either File or DatePattern options are not set for appender [myThreadfile].
{"data":["Total",447554,447554,100,784,957,1244,1083.637,301.5501,2,3789],"isController":false}
["Label","#Samples","KO","Error %","90th pct","95th pct","99th pct","Throughput","KB/sec","Min","Max"]
[{"data":["API端查询接口",447554,447554,100,784,957,1244,1083.637,301.5501,2,3789],"isController":false}]


0 0