Example usage for org.json.simple JSONArray JSONArray

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

Introduction

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

Prototype

JSONArray

Source Link

Usage

From source file:ListOfCitys.CityList.java

private static String getCountryName(String zone) throws IOException {
    String[] arry = zone.split(";"); //EU;DE
    zone = arry[1];// www .java 2 s . com
    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.aerothai.database.device.DeviceService.java

public JSONObject GetDeviceAll(int idunit, String opt) throws Exception {

    Connection dbConn = null;//www  .ja v a2s .  com
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "list");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM device";

        if (idunit > 0) {
            query = query + " WHERE idunit =" + idunit;
            if (isNotNull(opt))
                query = query + " AND " + opt;
        } else {
            if (isNotNull(opt))
                query = "SELECT * FROM device WHERE" + opt;
        }

        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("iddevice"));
            jsonData.put("idunit", rs.getString("idunit"));
            jsonData.put("iddevice_type", rs.getString("iddevice_type"));
            jsonData.put("idmodel", rs.getString("idmodel"));
            jsonData.put("idaccessory", rs.getString("idaccessory"));
            jsonData.put("asset_no", rs.getString("asset_no"));
            jsonData.put("serial_no", rs.getString("serial_no"));
            jsonData.put("ip_address", rs.getString("ip_address"));
            jsonData.put("mac_address", rs.getString("mac_address"));
            jsonData.put("computer_name", rs.getString("computer_name"));
            jsonData.put("os", rs.getString("os"));
            jsonData.put("firmware", rs.getString("firmware"));
            jsonData.put("vendor", rs.getString("vendor"));
            jsonData.put("customer", rs.getString("customer"));
            jsonData.put("address", rs.getString("address"));
            jsonData.put("location", rs.getString("location"));
            jsonData.put("insert_date", rs.getString("insert_date"));
            jsonData.put("receive_date", rs.getString("receive_date"));
            jsonData.put("exp_date", rs.getString("exp_date"));
            jsonData.put("image", rs.getString("image"));
            jsonData.put("id_door", rs.getString("id_door"));
            jsonData.put("in_out_side", rs.getString("in_out_side"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;

        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:modelo.AutenticacionManager.PermisosAcceso.java

public JSONArray SeleccionarPermisos(String rol) throws SQLException {

    JSONArray permisos = new JSONArray();
    JSONArray ArrayPantallas = new JSONArray();
    JSONObject modulos = new JSONObject();
    JSONObject pantallas = new JSONObject();
    Boolean flag = true;//  www. j  a v  a2s .  c o m
    String modulo = "";
    String codigo_modulo = "";
    SeleccionarPermisos select = new SeleccionarPermisos();

    ResultSet result = select.getModulos();

    while (result.next()) {

        modulo = result.getString("VAR_MODULO");
        codigo_modulo = result.getString("PK_CODIGO");
        modulos.put("modulo", modulo);

        ResultSet rstPantallas = select.getPantallas(rol, codigo_modulo);

        while (rstPantallas.next()) {

            pantallas.put("codigo", rstPantallas.getString("PK_CODIGO"));
            pantallas.put("jsp", rstPantallas.getString("VAR_PANTALLA"));
            pantallas.put("pantalla", rstPantallas.getString("VAR_DESCRIPCION"));
            pantallas.put("existe", rstPantallas.getString("EXISTE"));

            ArrayPantallas.add(pantallas.clone());
            pantallas.clear();
        }

        modulos.put("pantallas", ArrayPantallas.clone());
        ArrayPantallas.clear();
        permisos.add(modulos.clone());
    }

    select.desconectar();
    return permisos;
}

From source file:logica.Array.java

public JSONArray crearJson(int tipo) {
    JSONArray Json = new JSONArray();
    if (tipo == 0)
        Json.addAll(array);//from  ww  w .ja  v a  2s  . c o  m
    else
        Json.addAll(arrayPC);
    System.out.println(Json);
    System.out.println(Json.get(1));
    return Json;

}

From source file:client.InterfaceSalon.java

/**
 * Creates new form InterfaceSalon//  ww w . j a  v  a2  s.  c o m
 * @param liste
 * @param client
 */
public InterfaceSalon(String liste, Client client) {
    initComponents();
    this.c = client;
    this.lobbyListJSON = new JSONArray();
    parser = new JSONParser();

    setLobbyList(liste);
}

From source file:com.amindorost.searchalgorithms.MainSearch.java

public MainSearch() {
    this.topology = null;
    this.src = null;
    this.dst = null;
    this.nodesQueue = null;
    this.resultJSON = new JSONObject();
    this.iterationJSONArray = new JSONArray();
    this.pathJSON = new JSONArray();
}

From source file:jQuery.PRIMO.Record.java

/**
 * Resolve dedup record string./* ww  w .  ja  v a 2s  . c  o  m*/
 *
 * @param dedupID the dedup id
 * @param request the request
 * @return a JSON array of record id's
 */
public static String resolveDedupRecord(String dedupID, HttpServletRequest request) {
    JSONArray obj = new JSONArray();

    try {

        if ((dedupID != null) && (dedupID.length() > 0)) {
            obj.addAll(Helpers.resolveDedupRecord(dedupID, request));
        }
    } catch (Exception e) {
        e.printStackTrace();
        obj.add(e.getMessage());
    }
    return obj.toJSONString();
}

From source file:co.alligo.toasted.Servers.java

public JSONArray getServers() {
    String[] serveruris = servers.keySet().toArray(new String[servers.keySet().size()]);
    JSONArray jsonarray = new JSONArray();

    for (int x = 0; x < serveruris.length; x++) {
        if ((servers.get(serveruris[x]) >= expirationTime)) {
            servers.remove(serveruris[x]);
        }//w  ww . ja  va 2  s.com
    }

    for (int x = 0; x < serveruris.length; x++)
        jsonarray.add(serveruris[x]);

    return jsonarray;
}

From source file:jsonconverter.createandwrite.JSONObjectCreator.java

public JSONObject objectArranger() {

    JSONArray array = new JSONArray();
    for (JSONSearchObjectCreator searchObject : arraySearchObjs) {
        JSONObject tempObj = new JSONObject();

        tempObj.put("id", searchObject.getId());
        tempObj.put("path", searchObject.getPath());
        tempObj.put("title", searchObject.getTitle());
        tempObj.put("frag", searchObject.getFragment());

        array.add(tempObj);//from  w  ww. j a v a2s  .com
    }

    obj.put("Search", array);

    return obj;
}

From source file:com.oic.event.map.GetMapUserList.java

@Override
public void ActionEvent(JSONObject json, WebSocketListener webSocket) {
    JSONObject responseJSON = new JSONObject();
    responseJSON.put("method", "getmapuserlist");
    if (!validation(json)) {
        responseJSON.put("status", 1);
        webSocket.sendJson(responseJSON);
        return;/*from  www.  j  ava 2 s  . c om*/
    }

    int mapid = Integer.parseInt(json.get("mapid").toString());
    MapFactory factory = MapFactory.getInstance();
    OicMap map = factory.getMap(mapid);
    JSONArray charactersJSON = new JSONArray();
    try {
        for (Long userid : map.getUserIdList()) {
            charactersJSON.add(userid);
        }
    } catch (NullPointerException ex) {
    }

    responseJSON.put("userlist", charactersJSON);
    webSocket.sendJson(responseJSON);
}