use of net.sf.json.JSONArray in project cachecloud by sohutv.
the class AppController method assembleJson.
private String assembleJson(List<AppCommandStats> appCommandStatsList, Integer addDay) {
if (appCommandStatsList == null || appCommandStatsList.isEmpty()) {
return "[]";
}
List<SimpleChartData> list = new ArrayList<SimpleChartData>();
for (AppCommandStats stat : appCommandStatsList) {
try {
SimpleChartData chartData = SimpleChartData.getFromAppCommandStats(stat, addDay);
list.add(chartData);
} catch (ParseException e) {
logger.info(e.getMessage(), e);
}
}
JSONArray jsonArray = JSONArray.fromObject(list);
return jsonArray.toString();
}
use of net.sf.json.JSONArray in project cachecloud by sohutv.
the class AppController method assembleAppStatsJson.
/**
* AppStats列表组装成json串
*/
private String assembleAppStatsJson(List<AppStats> appStats, String statName) {
if (appStats == null || appStats.isEmpty()) {
return "[]";
}
List<SimpleChartData> list = new ArrayList<SimpleChartData>();
for (AppStats stat : appStats) {
try {
SimpleChartData chartData = SimpleChartData.getFromAppStats(stat, statName);
list.add(chartData);
} catch (ParseException e) {
logger.info(e.getMessage(), e);
}
}
JSONArray jsonArray = JSONArray.fromObject(list);
return jsonArray.toString();
}
use of net.sf.json.JSONArray in project zaproxy by zaproxy.
the class ApiResponseList method toJSON.
@Override
public JSON toJSON() {
if (list == null) {
return null;
}
JSONObject jo = new JSONObject();
JSONArray array = new JSONArray();
for (ApiResponse resp : this.list) {
if (resp instanceof ApiResponseElement) {
array.add(((ApiResponseElement) resp).getValue());
} else {
array.add(resp.toJSON());
}
}
jo.put(getName(), array);
return jo;
}
use of net.sf.json.JSONArray in project compiler by boalang.
the class GetGitHubRepoNames method main.
public static void main(String[] args) {
File inDir = new File(Config.githubRepoListDir);
StringBuilder sb = new StringBuilder();
for (File file : inDir.listFiles()) {
if (file.getName().endsWith(".json")) {
String jsonTxt = "";
try {
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
byte[] bytes = new byte[(int) file.length()];
in.read(bytes);
in.close();
jsonTxt = new String(bytes);
} catch (Exception e) {
System.err.println("Error reading file " + file.getAbsolutePath());
continue;
}
if (jsonTxt.isEmpty()) {
System.err.println("File is empty " + file.getAbsolutePath());
continue;
}
//System.out.println(jsonTxt);
JSONArray repos = null;
try {
repos = (JSONArray) JSONSerializer.toJSON(jsonTxt);
} catch (JSONException e) {
}
if (repos == null) {
System.err.println("Error parsing file " + file.getAbsolutePath());
continue;
}
for (int i = 0; i < repos.size(); i++) {
//System.out.println(repos.getJSONObject(i));
JSONObject repo = repos.getJSONObject(i);
String id = repo.getString("id");
String name = repo.getString("full_name");
System.out.println(id + ": " + name);
sb.append(id + "," + name + "\n");
//FileIO.writeFileContents(new File(Config.githubRepoMetadataDir + "/" + id + ".json"), repo.toString());
}
}
}
FileIO.writeFileContents(new File(inDir.getParentFile().getAbsolutePath() + "/list.csv"), sb.toString());
}
use of net.sf.json.JSONArray in project bamboobsc by billchen198318.
the class KpiReportCoffeeChartJsonDataCommand method setJsonData.
private void setJsonData(Context context, BscStructTreeObj treeObj) throws Exception {
if (treeObj == null || treeObj.getVisions() == null || treeObj.getVisions().size() != 1) {
return;
}
List<Map<String, Object>> rootList = new ArrayList<Map<String, Object>>();
Map<String, Object> rootDataMap = new HashMap<String, Object>();
List<Map<String, Object>> perspectivesDatas = new ArrayList<Map<String, Object>>();
List<VisionVO> visions = treeObj.getVisions();
VisionVO vision = visions.get(0);
for (PerspectiveVO perspective : vision.getPerspectives()) {
Map<String, Object> perspectiveDataMap = new HashMap<String, Object>();
List<Map<String, Object>> perspectiveChildren = new ArrayList<Map<String, Object>>();
perspectiveDataMap.put("name", this.getName(perspective.getName(), perspective.getScore()));
perspectiveDataMap.put("children", perspectiveChildren);
perspectiveDataMap.put("colour", perspective.getBgColor());
perspectiveDataMap.put("fontColor", perspective.getFontColor());
perspectiveDataMap.put("score", perspective.getScore());
perspectivesDatas.add(perspectiveDataMap);
for (ObjectiveVO objective : perspective.getObjectives()) {
Map<String, Object> objectiveDataMap = new HashMap<String, Object>();
List<Map<String, Object>> objectiveChildren = new ArrayList<Map<String, Object>>();
objectiveDataMap.put("name", this.getName(objective.getName(), objective.getScore()));
objectiveDataMap.put("children", objectiveChildren);
objectiveDataMap.put("colour", objective.getBgColor());
objectiveDataMap.put("fontColor", objective.getFontColor());
objectiveDataMap.put("score", objective.getScore());
perspectiveChildren.add(objectiveDataMap);
for (KpiVO kpi : objective.getKpis()) {
Map<String, Object> indicatorsDataMap = new HashMap<String, Object>();
indicatorsDataMap.put("name", this.getName(kpi.getName(), kpi.getScore()));
indicatorsDataMap.put("colour", kpi.getBgColor());
indicatorsDataMap.put("fontColor", kpi.getFontColor());
indicatorsDataMap.put("score", kpi.getScore());
objectiveChildren.add(indicatorsDataMap);
}
}
}
rootDataMap.put("name", this.getName(vision.getTitle(), vision.getScore()));
rootDataMap.put("children", perspectivesDatas);
rootDataMap.put("colour", vision.getBgColor());
rootDataMap.put("fontColor", vision.getFontColor());
rootDataMap.put("score", vision.getScore());
rootList.add(rootDataMap);
String jsonDataStr = ((JSONArray) JSONSerializer.toJSON(rootList)).toString();
this.setResult(context, jsonDataStr);
}
Aggregations