Java 类org.json.simple.JSONWriter 实例源码

项目:Cognizant-Intelligent-Test-Scripter    文件:ParseJSON.java   
public String readJSON() {

        try {
            Object obj = parser.parse(new FileReader(jsonFile));
            JSONObject jsonObject = (JSONObject) obj;
            jsonString = JSONWriter.getJSONString(jsonObject);
        } catch (IOException | ParseException ex) {
            Logger.getLogger(ParseJSON.class.getName()).log(Level.SEVERE, null, ex);
        }
        return jsonString;
    }
项目:Cognizant-Intelligent-Test-Scripter    文件:ParseJSON.java   
public void saveJson(ObservableList<Browsers> data, String svrIP, String srvPort, long clientPort, long mxBrInst) {
    JSONObject mainObj = new JSONObject();
    JSONArray capList = new JSONArray();
    for (int i = 0; i < data.size(); i++) {
        if (!data.get(i).getBrowser().isEmpty() && !data.get(i).getMaxInst().isEmpty()) {
            JSONObject cap = new JSONObject();
            cap.put("browserName", data.get(i).getBrowser());
            cap.put("maxInstances", Long.parseLong(data.get(i).getMaxInst()));
            cap.put("seleniumProtocol", "WebDriver");
            capList.add(cap);
        } else {
            Logger.getLogger(ParseJSON.class.getName()).log(Level.WARNING, "The empty browser fields in the table won't be saved!", "");
        }
    }
    mainObj.put("capabilities", capList);
    mainObj.put("proxy", "org.openqa.grid.selenium.proxy.DefaultRemoteProxy");
    mainObj.put("maxSession", mxBrInst);
    mainObj.put("port", clientPort);
    mainObj.put("register", true);
    mainObj.put("registerCycle", 5000);
    mainObj.put("hub", "http://" + svrIP + ":" + srvPort);

    try (FileWriter file = new FileWriter(jsonFile)) {
        file.write(JSONWriter.getJSONString(mainObj));
        file.flush();
    } catch (IOException ex) {
        Logger.getLogger(ParseJSON.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:Star-Sector    文件:Config.java   
public void save() throws IOException
{
    File configFile = new File(path);
    FileWriter writer = new FileWriter(configFile);
    JSONWriter out = new JSONWriter();

    config.writeJSONString(out);

    writer.write(out.toString());
    writer.flush();
    writer.close();
}