Example usage for org.json.simple JSONArray add

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

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:net.duckling.ddl.web.controller.message.RecommendController.java

@SuppressWarnings("unchecked")
private void getTeamAllUser(VWBContext ctx, HttpServletResponse response) {
    List<SimpleUser> candidates = teamMemberService.getTeamMembersOrderByName(ctx.getTid());
    Collections.sort(candidates, comparator);
    JSONArray array = new JSONArray();
    for (SimpleUser current : candidates) {
        JSONObject temp = new JSONObject();
        temp.put("uid", current.getUid());
        temp.put("id", current.getId());
        temp.put("email", current.getEmail());
        temp.put("pinyin", current.getPinyin());
        if (StringUtils.isNotEmpty(current.getName())) {
            temp.put("name", current.getName());
        } else {/* w  w  w.j  av  a  2 s .c  o  m*/
            temp.put("name", current.getUid());
        }
        array.add(temp);
    }
    JsonUtil.writeJSONObject(response, array);
}

From source file:net.duckling.ddl.web.controller.task.TaskBaseController.java

private void add2Array(JSONArray parent, JSONArray child, char alphabet) {
    JSONObject obj = new JSONObject();
    obj.put("id", "" + alphabet);
    obj.put("value", child);
    parent.add(obj);
}

From source file:com.imagelake.control.InterfaceDAOImp.java

public String listInterfaces() {
    String sb = "";
    JSONArray ja = new JSONArray();
    try {//from   w  w  w  .  j a v  a2  s .  co  m
        String sql = "SELECT * FROM interfaces";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);

        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            JSONObject jo = new JSONObject();
            jo.put("id", rs.getInt(1));
            jo.put("name", rs.getString(3));
            jo.put("state", rs.getInt(4));
            ja.add(jo);

        }
        sb = "json=" + ja.toJSONString();
    } catch (Exception e) {
        e.printStackTrace();
        sb = "msg=Internal server error,Please try again later.";
    }
    return sb;
}

From source file:modelo.ProcesoVertimientosManagers.ProgramarMonitoreo.java

/**
* 
* Llama al delegate que valida si existe un monitoreo activo para un proceso
* 
* @param codigo     /*  w  ww . ja v  a2s.c  om*/
* @throws Exception 
*/
public JSONArray validarMonitoreoAct(int codigo) throws Exception {

    JSONArray jsonArray = new JSONArray();
    JSONObject jsonObject = new JSONObject();

    Integer resultado;

    ValidarMonitoreosActivos validate = new ValidarMonitoreosActivos(codigo);
    validate.ejecutar();

    resultado = validate.getResultado();

    jsonObject.put("resultado", resultado);

    jsonArray.add(jsonObject);

    return jsonArray;

}

From source file:com.wso2telco.dep.mediator.executor.ExecutorInfoHostObject.java

private NativeArray getHandlerObjects() {

    Object[] values = handlers.values().toArray();
    NativeArray nativeArray = new NativeArray(1);
    JSONArray jsonArray = new JSONArray();

    for (Object obj : values) {

        HandlerObj object = (HandlerObj) obj;
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("handlerName", object.getHandlerName());
        jsonObject.put("handlerFQN", object.getHandlerFullQulifiedName());

        jsonArray.add(jsonObject);

        //NativeObject nativeObject = new NativeObject();
        //nativeObject.put(object.getHandlerName(), nativeObject, object.getHandlerFullQulifiedName());
    }/*from   ww  w.j a  v  a 2 s  . c o m*/

    nativeArray.put(0, nativeArray, jsonArray.toJSONString());
    return nativeArray;
}

From source file:API.JSONPractice.java

private void getMatch() throws Exception {

    Integer[] apIds = { 1026, 1052, 1056, 1058, 3001, 3003, 3020, 3023, 3025, 3027, 3040, 3041, 3050, 3057,
            3060, 3089, 3092, 3098, 3100, 3108, 3113, 3115, 3116, 3124, 3135, 3136, 3145, 3146, 3151, 3152,
            3157, 3165, 3174, 3191, 3285, 3303, 3504, 3708, 3716, 3720, 3724 };
    List<Integer> apIdsList = Arrays.asList(apIds);

    Files.walk(Paths.get("C:\\AP_ITEMS\\")).forEach(filePath -> {
        if (Files.isRegularFile(filePath)) {

            try (FileReader fileReader = new FileReader(filePath.toString())) {

                File file = new File(filePath.toString());
                String fileName = file.getName();
                String region = fileName.replace(".json", "").toLowerCase();

                JSONParser jsonParser = new JSONParser();
                JSONArray matchId = (JSONArray) jsonParser.parse(fileReader);

                for (int i = 0; i < jsonFileSize; i++) {

                    url = "https://" + region + ".api.pvp.net/api/lol/" + region + "/v2.2/match/"
                            + matchId.get(i) + "?api_key=" + api_key;

                    System.out.println(url);

                    File jsonFile = new File("C:\\Riot_API\\" + region + "\\" + matchId.get(i) + ".json");

                    if (!jsonFile.exists()) {
                        FileWriter fileWriter = new FileWriter(jsonFile);
                        BufferedWriter bw = new BufferedWriter(fileWriter);

                        URL obj = new URL(url);
                        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

                        do {
                            // optional default is GET
                            con.setRequestMethod("GET");

                            int responseCode = con.getResponseCode();
                            System.out.println("\nSending 'GET' request to URL : " + url);
                            System.out.println("Response Code : " + responseCode);

                            if (responseCode == 500 || responseCode == 503) {
                                tryAgain = true;
                            } else {
                                tryAgain = false;
                            }//from w ww. jav a 2  s .  c o  m
                        } while (tryAgain);

                        StringBuffer response = new StringBuffer();

                        try (BufferedReader in = new BufferedReader(
                                new InputStreamReader(con.getInputStream()))) {
                            String inputLine;

                            while ((inputLine = in.readLine()) != null) {
                                response.append(inputLine);
                            }

                            // do try
                            in.close();

                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                        JSONObject jsonObject = new JSONObject(response.toString());

                        for (int n = 0; n < numberOfParticipants; n++) {

                            JSONObject stats = jsonObject.getJSONArray("participants").getJSONObject(n)
                                    .getJSONObject("stats");
                            JSONObject object = new JSONObject();
                            JSONArray arr = new JSONArray();

                            // String test = jsonObject.getJSONArray("participants").getJSONObject(i).getJSONObject("timeline").getString("lane");
                            for (int count = 0; count < itemSlots; count++) {
                                if (stats.getInt("item" + count) != 0) {
                                    arr.add(stats.getInt("item" + count));
                                    itemList.add(stats.getInt("item" + count));
                                }
                            }

                            object.put("participant" + (n + 1), arr);
                            bw.write(object.toString());
                        }
                        bw.flush();
                        bw.close();
                    }
                    /*
                     for (int itemId : itemList) {
                     if (apIdsList.contains(itemId)) {
                     fullApList.add(itemId);
                     }
                     }
                     */

                    // Sleep count came from request limit of 500 request per 10 minute.
                    // Therefore, 1.2 sec per request is allowed.
                    Thread.sleep(1200);
                }

                NumberFormat defaultFormat = NumberFormat.getPercentInstance();
                defaultFormat.setMinimumFractionDigits(1);
                /*
                                    for (int value : apIdsList) {
                double occurrences = Collections.frequency(fullApList, value);
                System.out.println(defaultFormat.format(occurrences / itemList.size()));
                                    }
                */
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    // } catch (FileNotFoundException | IOException | ParseException e)        
}

From source file:net.duckling.ddl.web.controller.pan.PanFileMoveController.java

private JSONArray getChildrenJSONArray(String rid, PanAcl panAcl) {
    JSONArray childrenJson = new JSONArray();
    MeePoMeta root;// w w w . ja v  a  2s  . c om
    try {
        root = service.ls(panAcl, decode(rid), true);
        List<PanResourceBean> beans = getChildren(root, aoneUserService.getSimpleUserByUid(panAcl.getUid()));
        for (PanResourceBean child : beans) {
            childrenJson.add(resourceToJSONObject(child.getRid(), false));
        }
    } catch (MeePoException e) {
        LOG.error("", e);
    }
    return childrenJson;
}

From source file:com.erbjuder.logger.server.entity.impl.LogMessage.java

public JSONObject toJSON() {

    JSONArray logMessageDataList = new JSONArray();
    //@TODO MUSt create separate query the return required information
    for (com.erbjuder.logger.server.entity.interfaces.LogMessageData data : this
            .getLogMessageData(DataBase.LOGMESSAGEDATA_PARTITION_CLASSES)) {
        logMessageDataList.add(data.toJSON());
    }/*from   w w w .  j a  v a  2s . c o m*/

    JSONObject node = new JSONObject();
    node.put("id", this.getId());
    node.put("isError", this.isIsError());
    node.put("applicationName", this.getApplicationName());
    node.put("expiredDate", this.getExpiredDate());
    node.put("utcLocalTimeStamp", this.getUtcLocalTimeStamp());
    node.put("utcServerTimeStamp", this.getUtcServerTimeStamp());
    node.put("flowName", this.getFlowName());
    node.put("flowPointName", this.getFlowPointName());
    //node.put("logMessageData", logMessageDataList);
    //node.put("logMessageMetaInfo", logMessageMetaInfoList);
    return node;

}

From source file:jp.aegif.nemaki.rest.GroupResource.java

@SuppressWarnings("unchecked")
@GET/*  ww  w.  j  a  v a 2 s  .com*/
@Path("/search")
@Produces(MediaType.APPLICATION_JSON)
public String search(@PathParam("repositoryId") String repositoryId, @QueryParam("query") String query) {
    boolean status = true;
    JSONObject result = new JSONObject();
    JSONArray errMsg = new JSONArray();

    List<Group> groups = this.principalService.getGroups(repositoryId);
    JSONArray queriedGroups = new JSONArray();

    for (Group g : groups) {
        if (g.getGroupId().startsWith(query) || g.getName().startsWith(query)) {
            queriedGroups.add(this.convertGroupToJson(g));
        }
    }

    if (queriedGroups.size() == 0) {
        status = false;
        addErrMsg(errMsg, ITEM_GROUP, ErrorCode.ERR_NOTFOUND);
    } else {
        result.put("result", queriedGroups);
    }

    result = makeResult(status, result, errMsg);
    return result.toString();
}

From source file:com.wso2telco.dep.mediator.executor.ExecutorInfoHostObject.java

private NativeArray getExecutorObjects() {

    Object[] values = executors.values().toArray();
    NativeArray nativeArray = new NativeArray(1);
    JSONArray jsonArray = new JSONArray();

    for (Object obj : values) {

        ExecutorObj executorObj = (ExecutorObj) obj;
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("executorName", executorObj.getExecutorName());
        jsonObject.put("executorFQN", executorObj.getFullQulifiedName());

        jsonArray.add(jsonObject);
    }//  w  w  w  .  j av  a 2s.c  o m

    nativeArray.put(0, nativeArray, jsonArray.toJSONString());
    return nativeArray;
}