Example #1
0
 /**
  * Construct a JSONObject from a subset of another JSONObject. An array of strings is used to
  * identify the keys that should be copied. Missing keys are ignored.
  *
  * @param jo A JSONObject.
  * @param names An array of strings.
  * @throws JSONException
  * @exception JSONException If a value is a non-finite number or if a name is duplicated.
  */
 public JSONObject(JSONObject jo, String[] names) {
   this();
   for (int i = 0; i < names.length; i += 1) {
     try {
       putOnce(names[i], jo.opt(names[i]));
     } catch (Exception ignore) {
     }
   }
 }
Example #2
0
  /**
   * Construct a JSONObject from a JSONTokener.
   *
   * @param x A JSONTokener object containing the source string.
   * @throws JSONException If there is a syntax error in the source string or a duplicated key.
   */
  public JSONObject(JSONTokener x) throws JSONException {
    this();
    char c;
    String key;

    if (x.nextClean() != '{') {
      throw x.syntaxError("A JSONObject text must begin with '{'");
    }
    for (; ; ) {
      c = x.nextClean();
      switch (c) {
        case 0:
          throw x.syntaxError("A JSONObject text must end with '}'");
        case '}':
          return;
        default:
          x.back();
          key = x.nextValue().toString();
      }

      /*
       * The key is followed by ':'. We will also tolerate '=' or '=>'.
       */

      c = x.nextClean();
      if (c == '=') {
        if (x.next() != '>') {
          x.back();
        }
      } else if (c != ':') {
        throw x.syntaxError("Expected a ':' after a key");
      }
      putOnce(key, x.nextValue());

      /*
       * Pairs are separated by ','. We will also tolerate ';'.
       */

      switch (x.nextClean()) {
        case ';':
        case ',':
          if (x.nextClean() == '}') {
            return;
          }
          x.back();
          break;
        case '}':
          return;
        default:
          throw x.syntaxError("Expected a ',' or '}'");
      }
    }
  }
 public static void distributeCommand(Command com) {
   for (MLProcess cur : programBuffer) {
     try {
       JSONObject toSend = new JSONObject();
       toSend.putOnce("ORIGIN", "CONTROLLER");
       toSend.put("ARGUMENT", "[]");
       toSend.put("COMMAND", com.toString());
       cur.queueForSending(toSend.toString());
     } catch (JSONException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
 public static void sendControllMessage(String cellData, String name) {
   for (MLProcess cur : programBuffer) {
     if (cur.getName().equals(name)) {
       try {
         JSONObject parseObject = new JSONObject(cellData);
         cur.queueForSending(parseObject.toString());
       } catch (JSONException e) {
         try {
           JSONObject emptyObject = new JSONObject();
           emptyObject.putOnce("ORIGIN", "CONTROLLER");
           emptyObject.put("ARGUMENT", "[]");
           emptyObject.put("COMMAND", cellData);
           cur.queueForSending(emptyObject.toString());
         } catch (JSONException e1) {
           System.out.println("Second JSON ERROR");
           e.printStackTrace();
         }
       }
     }
   }
 }
Example #5
0
 /**
  * Construct a JSONObject from a subset of another JSONObject. An array of strings is used to
  * identify the keys that should be copied. Missing keys are ignored.
  *
  * @param jo A JSONObject.
  * @param names An array of strings.
  * @exception JSONException If a value is a non-finite number or if a name is duplicated.
  */
 public JSONObject(JSONObject jo, String[] names) throws JSONException {
   this();
   for (int i = 0; i < names.length; i += 1) {
     putOnce(names[i], jo.opt(names[i]));
   }
 }