Esempio n. 1
0
  @SuppressWarnings("rawtypes")
  public List<Code> GetCodeCache() {
    List<Code> list = new ArrayList<Code>();

    if (MemCached.used()) {
      Object obj = MemCached.getInstance().get("Code");
      if (obj != null && !obj.equals("")) {
        String json = MemCached.getInstance().get("Code").toString();

        JSONArray array = JSONArray.fromObject(json);
        for (Iterator iter = array.iterator(); iter.hasNext(); ) {
          JSONObject jsonObject = (JSONObject) iter.next();
          list.add((Code) JSONObject.toBean(jsonObject, Code.class));
        }
      } else {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("status", "Y");
        list = this.findForUnPage(params);

        JSONArray jsonObject = JSONArray.fromObject(list);

        MemCached.getInstance().set("Code", jsonObject);
      }
    }

    return list;
  }
 public void setArrayFixed(JSONArray array, boolean fixed) {
   Iterator i = array.iterator();
   while (i.hasNext()) {
     JSONObject object = (JSONObject) i.next();
     object = this.setFixedRecursive(object, fixed);
   }
 }
 public JSONObject objectForTargetXPath(JSONArray array, String xpath) {
   Iterator i = array.iterator();
   while (i.hasNext()) {
     JSONObject object = (JSONObject) i.next();
     JSONObject result = this.objectForTargetXPath(object, xpath);
     if (result != null) return result;
   }
   return null;
 }
Esempio n. 4
0
 @SuppressWarnings("unchecked")
 public static List<ChaseWait> convertFromJSONArray(JSONArray array) {
   if (array == null) {
     return null;
   }
   List<ChaseWait> list = new ArrayList<ChaseWait>();
   for (Iterator iterator = array.iterator(); iterator.hasNext(); ) {
     JSONObject object = (JSONObject) iterator.next();
     list.add(convertFromJSONObject(object));
   }
   return list;
 }
Esempio n. 5
0
 /**
  * 게임별 랭킹 1 ~ 100 까지의 순위 데이터 파싱한다.
  *
  * @param res
  */
 public static void print_list(String res) {
   JSONObject jo = JSONObject.fromObject(res);
   System.out.println("ngcIfId : " + jo.getString("ngcIfId"));
   System.out.println("result : " + jo.getString("result"));
   System.out.println("totalCount : " + jo.getString("totalCount"));
   JSONArray ja = jo.getJSONArray("rankList");
   int a = 0;
   System.out.println("print array");
   for (Iterator i = ja.iterator(); i.hasNext(); ) {
     JSONObject ob = (JSONObject) i.next();
     String mdn = ob.getString("mdn");
     String rank = ob.getString("rank");
     System.out.println("[" + a + "]" + mdn + ":" + rank);
     a++;
   }
 }
  public JSONObject getTargetDefinition() {
    JSONArray groups = this.targetDefinition.getJSONArray("groups");
    Iterator i = groups.iterator();
    while (i.hasNext()) {
      JSONObject item = (JSONObject) i.next();
      String element = item.getString("element");
      item.put("contents", this.getElementDescription(element));
    }

    if (!this.targetDefinition.has("template")
        || this.targetDefinition.getJSONObject("template").isEmpty()) {
      JSONObject template =
          this.buildTemplate(this.targetDefinition.getJSONObject("item").getString("element"));
      this.templateCache = template;
      this.cacheElements(this.templateCache);
    }

    this.targetDefinition.put("template", this.templateCache);

    return this.targetDefinition;
  }
Esempio n. 7
0
  public static void sample() {
    System.out.println("jsontestmain");

    String s =
        "{\"rankList\":[{\"mdn\":\"01033334444\",\"rank\": 1 },{\"mdn\":\"01088881111\",\"rank\": 2}],\"ngcIfId\":\"NGC_GAME_RANK\",\"result\":\"NGC0000\",\"totalCount\":2}";
    System.out.println("origin:" + s);

    JSONObject jo = JSONObject.fromObject(s);
    System.out.println("ngcIfId : " + jo.getString("ngcIfId"));
    System.out.println("result : " + jo.getString("result"));
    System.out.println("totalCount : " + jo.getString("totalCount"));
    JSONArray ja = jo.getJSONArray("rankList");
    int a = 0;
    System.out.println("print array");
    for (Iterator i = ja.iterator(); i.hasNext(); ) {
      JSONObject ob = (JSONObject) i.next();
      String mdn = ob.getString("mdn");
      String rank = ob.getString("rank");
      System.out.println("[" + a + "]" + mdn + ":" + rank);
      a++;
    }
  }
Esempio n. 8
0
  public static String getJSONuiLabelArray(
      HttpServletRequest request, HttpServletResponse response) {
    String requiredLabels = request.getParameter("requiredLabels");

    JSONObject uiLabelObject = null;
    if (UtilValidate.isNotEmpty(requiredLabels)) {
      // Transform JSON String to Object
      uiLabelObject = (JSONObject) JSONSerializer.toJSON(requiredLabels);
    }

    JSONObject jsonUiLabel = new JSONObject();
    Locale locale = request.getLocale();
    if (!uiLabelObject.isEmpty()) {
      Set<String> resourceSet = UtilGenerics.checkSet(uiLabelObject.keySet());
      // Iterate over the resouce set
      for (String resource : resourceSet) {
        JSONArray labels = uiLabelObject.getJSONArray(resource);
        if (labels.isEmpty() || labels == null) {
          continue;
        }

        // Iterate over the uiLabel List
        Iterator<String> jsonLabelIterator = UtilGenerics.cast(labels.iterator());
        JSONArray resourceLabelList = new JSONArray();
        while (jsonLabelIterator.hasNext()) {
          String label = jsonLabelIterator.next();
          String receivedLabel = UtilProperties.getMessage(resource, label, locale);
          if (UtilValidate.isNotEmpty(receivedLabel)) {
            resourceLabelList.add(receivedLabel);
          }
        }
        jsonUiLabel.element(resource, resourceLabelList);
      }
    }

    writeJSONtoResponse(jsonUiLabel, response);
    return "success";
  }