Example usage for org.json.simple JSONArray toJSONString

List of usage examples for org.json.simple JSONArray toJSONString

Introduction

In this page you can find the example usage for org.json.simple JSONArray toJSONString.

Prototype

public String toJSONString() 

Source Link

Usage

From source file:jo.alexa.sim.ui.logic.RuntimeLogic.java

private static void saveMRUs(RuntimeBean runtime) {
    JSONArray jspecs = ToJSONLogic.toJSONAppSpecs(runtime.getMRUs());
    setProp("app.mrus", jspecs.toJSONString());
}

From source file:at.ac.tuwien.dsg.quelle.sesConfigurationsRecommendationService.util.ConvertTOJSON.java

public static String convertTOJSON(List<Metric> metrics) {
    JSONArray children = new JSONArray();

    for (Metric m : metrics) {
        JSONObject metricJSON = new JSONObject();
        metricJSON.put("name", m.getName());
        metricJSON.put("unit", m.getMeasurementUnit());
        metricJSON.put("type", "" + m.getType());
        children.add(metricJSON);//from w w w  .ja va2  s .  c  om
    }

    return children.toJSONString();
}

From source file:it.cnr.isti.thematrix.scripting.sys.DatasetSchema.java

/**
 * Converts the argument schema into a JSON String
 * @param schema//from  w  ww  . j a v  a2 s  .  c  o m
 * @return he argument schema into a JSON String
 */
public static String toJSON(DatasetSchema schema) {
    JSONArray list = new JSONArray();
    list.add(schema.name);
    for (Symbol<?> s : schema.attributes()) {
        JSONObject obj = new JSONObject();
        obj.put("name", s.name);
        obj.put("type", s.type.toString());
        list.add(obj);
    }

    return list.toJSONString();
}

From source file:jo.alexa.sim.ui.logic.RuntimeLogic.java

public static void saveHistory(RuntimeBean runtime, File source) throws IOException {
    JSONArray transs = ToJSONLogic.toJSONTransactions(runtime.getHistory());
    OutputStream os = new FileOutputStream(source);
    Writer wtr = new OutputStreamWriter(os, "utf-8");
    wtr.write(transs.toJSONString());
    wtr.close();//from w  w w  .  ja  v a 2s . c  o  m
    setProp("app.history", source.toString());
}

From source file:ListOfCitys.CityList.java

private static String getCountryName(String zone) throws IOException {
    String[] arry = zone.split(";"); //EU;DE
    zone = arry[1];//from   w  w  w. jav a 2 s . c  o m
    String[] locales = Locale.getISOCountries();
    String countryName = "";
    JSONArray countryWithCities = new JSONArray();
    Map<String, List<String>> countryWithCityNames = new HashMap<>();
    for (String countryCode : locales) {
        Locale obj = new Locale("", countryCode);
        System.out
                .println("Country Code = " + obj.getCountry() + ", Country Name = " + obj.getDisplayCountry());
        countryWithCities.add(getCityNameForCountry(obj.getCountry(), countryCode));
        if (obj.getCountry().equalsIgnoreCase(zone)) {
            countryName = obj.getDisplayCountry();
            break;
        }
    }
    System.out.println("-----json array --- " + countryWithCities.toJSONString());
    try (FileWriter file = new FileWriter("test.json")) {
        file.write(countryWithCities.toJSONString());
    }
    return countryName;
}

From source file:com.healthcit.analytics.utils.ExcelExportUtils.java

@SuppressWarnings("unchecked")
public static void streamVisualizationDataAsExcelFormat(OutputStream out, JSONObject data) {
    // Get the array of columns
    JSONArray jsonColumnArray = (JSONArray) data.get(COLUMNS_JSON_KEY);

    String[] excelColumnArray = new String[jsonColumnArray.size()];

    for (int index = 0; index < excelColumnArray.length; ++index) {
        excelColumnArray[index] = (String) ((JSONObject) jsonColumnArray.get(index)).get(LABEL_JSON_KEY);
    }/*from   w w w. j  ava 2 s .  co  m*/

    // Get the array of rows
    JSONArray jsonRowArray = (JSONArray) data.get(ROWS_JSON_KEY);

    JSONArray excelRowArray = new JSONArray();

    Iterator<JSONObject> jsonRowIterator = jsonRowArray.iterator();

    while (jsonRowIterator.hasNext()) {
        JSONArray rowCell = (JSONArray) jsonRowIterator.next().get(ROWCELL_JSON_KEY);

        JSONObject excelRowObj = new JSONObject();

        for (int index = 0; index < rowCell.size(); ++index) {

            excelRowObj.put(excelColumnArray[index],
                    ((JSONObject) rowCell.get(index)).get(ROWCELLVALUE_JSON_KEY));
        }

        excelRowArray.add(excelRowObj);
    }

    // build the Excel outputstream
    Json2Excel.build(out, excelRowArray.toJSONString(), excelColumnArray);
}

From source file:net.sourceforge.fenixedu.webServices.jersey.services.JerseyServices.java

@GET
@Produces(MediaType.APPLICATION_JSON)//from   w ww .  j  ava2 s  .  c om
@Path("readAllStudentsInfoForJobBank")
public static String readAllStudentsInfoForJobBank() {
    ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear();
    Set<Registration> registrations = new HashSet<Registration>();
    LocalDate today = new LocalDate();
    for (Registration registration : Bennu.getInstance().getRegistrationsSet()) {
        if (registration.hasAnyActiveState(currentExecutionYear) && registration.isBolonha()
                && !registration.getDegreeType().equals(DegreeType.EMPTY)) {
            registrations.add(registration);
        }
    }
    for (ConclusionProcess conclusionProcess : Bennu.getInstance().getConclusionProcessesSet()) {
        if (conclusionProcess.getConclusionDate() != null
                && !conclusionProcess.getConclusionDate().plusYears(1).isBefore(today)) {
            registrations.add(conclusionProcess.getRegistration());
        }
    }
    JSONArray infos = new JSONArray();
    for (Registration registration : registrations) {
        infos.add(getStudentInfoForJobBank(registration));
    }
    return infos.toJSONString();
}

From source file:com.avatarproject.core.storage.UserCache.java

/**
 * Adds a player into the custom UserCache.
 * @param player Player to add to the cache.
 *//*from   w w  w .  j  a  v  a 2 s.  com*/
@SuppressWarnings("unchecked")
public static void addUser(Player player) {
    String name = player.getName();
    UUID uuid = player.getUniqueId();
    JSONArray array = getUserCache();
    try {
        for (int n = 0; n < array.size(); n++) { //Loop through all the objects in the array.
            JSONObject object = (JSONObject) array.get(n);
            if (object.get("id").equals(uuid.toString())) { //Check if the player's UUID exists in the cache.
                if (String.valueOf(object.get("name")).equalsIgnoreCase(name)) {
                    return;
                } else {
                    object.put("name", name); //Update the user.
                    FileWriter fileOut = new FileWriter(usercache);
                    fileOut.write(array.toJSONString()); //Write the JSON array to the file.
                    fileOut.close();
                    return;
                }
            }
        }
        JSONObject newEntry = new JSONObject();
        newEntry.put("id", uuid.toString());
        newEntry.put("name", name);
        array.add(newEntry); //Add a new player into the cache.
        FileWriter fileOut = new FileWriter(usercache);
        fileOut.write(array.toJSONString()); //Write the JSON array to the file.
        fileOut.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.doubotis.restwrapper.data.JArray.java

@Override
public String toJSONString() {

    JSONArray jsonArray = new JSONArray();
    jsonArray.addAll(this);
    return jsonArray.toJSONString();
}

From source file:com.facebook.tsdb.tsdash.server.MetricsEndpoint.java

@Override
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {/*  w  w w.  j  a  v  a2 s.c  om*/
        TsdbDataProvider dataProvider = TsdbDataProviderFactory.get();
        String[] metrics = dataProvider.getMetrics();
        response.setContentType("text/plain");
        JSONArray encoded = new JSONArray();
        for (String metric : metrics) {
            encoded.add(metric);
        }
        out.println(encoded.toJSONString());
    } catch (Exception e) {
        out.println(getErrorResponse(e));
    }
    out.close();
}