Search in sources :

Example 11 with JSONArray

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();
}
Also used : ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) SimpleChartData(com.sohu.cache.web.chart.model.SimpleChartData) ParseException(java.text.ParseException)

Example 12 with JSONArray

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();
}
Also used : ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) SimpleChartData(com.sohu.cache.web.chart.model.SimpleChartData) ParseException(java.text.ParseException)

Example 13 with JSONArray

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;
}
Also used : JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray)

Example 14 with JSONArray

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());
}
Also used : JSONObject(net.sf.json.JSONObject) BufferedInputStream(java.io.BufferedInputStream) JSONArray(net.sf.json.JSONArray) JSONException(net.sf.json.JSONException) File(java.io.File) FileInputStream(java.io.FileInputStream) JSONException(net.sf.json.JSONException)

Example 15 with JSONArray

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);
}
Also used : HashMap(java.util.HashMap) ObjectiveVO(com.netsteadfast.greenstep.vo.ObjectiveVO) ArrayList(java.util.ArrayList) KpiVO(com.netsteadfast.greenstep.vo.KpiVO) JSONArray(net.sf.json.JSONArray) PerspectiveVO(com.netsteadfast.greenstep.vo.PerspectiveVO) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JSONArray (net.sf.json.JSONArray)31 JSONObject (net.sf.json.JSONObject)19 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)5 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)4 Test (org.junit.Test)4 CommandStatus (com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)3 ProcessorStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)3 SimpleChartData (com.sohu.cache.web.chart.model.SimpleChartData)3 ParameterDefinition (hudson.model.ParameterDefinition)3 ParameterValue (hudson.model.ParameterValue)3 OutputStream (java.io.OutputStream)3 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)2 Pair (com.alibaba.cobar.manager.util.Pair)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 Method (java.lang.reflect.Method)2 ParseException (java.text.ParseException)2 Iterator (java.util.Iterator)2