Пример #1
0
 protected static Object[] parseArray(String string) {
   try {
     JSONArray array = new JSONArray(string);
     Object[] result = new Object[array.length()];
     for (int i = 0; i < result.length; i++) {
       result[i] = array.get(i);
     }
     return result;
   } catch (JSONException e) {
     throw new IllegalArgumentException(e.getMessage(), e);
   }
 }
Пример #2
0
  protected static Map<String, Object> parseFilter(String filterString, Output out)
      throws RemoteException, ShellException {
    if (filterString == null) {
      return new HashMap<String, Object>();
    }

    Map<String, Object> map = null;
    String signsOfJSON = ":";
    int numberOfSigns = 0;
    for (int i = 0; i < signsOfJSON.length(); i++) {
      if (filterString.contains(String.valueOf(signsOfJSON.charAt(i)))) {
        numberOfSigns++;
      }
    }

    if (numberOfSigns >= 1) {
      String jsonString = filterString;
      if (!jsonString.startsWith("{")) {
        jsonString = "{" + jsonString;
      }
      if (!jsonString.endsWith("}")) {
        jsonString += "}";
      }
      try {
        map = parseJSONMap(jsonString);
      } catch (JSONException e) {
        out.println(
            "parser: \""
                + filterString
                + "\" hasn't got "
                + "correct JSON formatting: "
                + e.getMessage());
        throw ShellException.wrapCause(e);
      }
    } else {
      map = new HashMap<String, Object>();
      map.put(filterString, null);
    }
    return map;
  }