Package org.json.me

Examples of org.json.me.JSONObject


            return "START OR STOP LED FLASHING BASED ON PATTERN AND DURATION";
        }
      private void parseJson(String jsonPattern) throws JSONException, NumberFormatException {
      try {
        JSONArray jsonArray = new JSONArray(jsonPattern);
        JSONObject jsonObj = null;
        Enumeration jsonKeys = null;
        String jsonObjKey = "";
        String hexColor = "";
        String onTime = "";
        String transitionTime = "";
        String patternArray [] = new String[10];
        String tmp = "";
        if (jsonArray != null && jsonArray.length() > 0) {
          // determine the total pattern array size
          int jsonItems = 0;
          for (int i = 0; i < jsonArray.length(); i++) {
            jsonObj = jsonArray.getJSONObject(i);
            jsonKeys = jsonObj.keys();
            while (jsonKeys.hasMoreElements()) {
              tmp = (String)jsonKeys.nextElement();
              jsonItems++;
            }
          }
          patternArray = new String[jsonItems];
        }
        int itemCount = 0;
        for (int i = 0; i < jsonArray.length(); i++) {
          jsonObj = jsonArray.getJSONObject(i);
          jsonKeys = jsonObj.keys();

          while (jsonKeys.hasMoreElements()) {
            jsonObjKey = (String) jsonKeys.nextElement();
            if (jsonObjKey.equalsIgnoreCase(HEX_COLOR)) {
              hexColor = jsonObj.getString(jsonObjKey);
              patternArray[itemCount] = hexColor;
              itemCount++;
              continue;
            } else if (jsonObjKey.equalsIgnoreCase(ON_DURATION)) {
              onTime = jsonObj.getString(jsonObjKey);
              patternArray[itemCount] = onTime;
              itemCount++;
              continue;
            } else if (jsonObjKey.equalsIgnoreCase(TRANSITION_TIME)) {
              transitionTime = jsonObj.getString(jsonObjKey);
              patternArray[itemCount] = transitionTime;
              itemCount++;
              continue;
            }
View Full Code Here


        int ordering = (args.length>=4) ? Integer.parseInt(args[3].toString()) : 0;
        int priority = (args.length>=5) ? Integer.parseInt(args[4].toString()) : 0;
       
        try
        {
          JSONObject context = new JSONObject(args[1].toString());
         
          SendCommand[] sendCommands = SendCommandRepository.getInstance().get(sendType,context,getAll);
         
          if(sendCommands != null && sendCommands.length > 0)
          {
            if(args.length >= 6 && args[5] != null)
            {
              try
              {
                JSONObject filterArgs = new JSONObject(args[5].toString());
                SendContextFilter filter = new SendContextFilter(filterArgs);
                for (int i = 0; i < sendCommands.length; i++)
                {
                  sendCommands[i].setSendCommandContextFilter(filter);
                }
View Full Code Here

      filter = filterArgs;
    }

    public JSONObject filterContext(SendCommand sendCommand)
    {
      JSONObject newContext = sendCommand.getContext();
      try
      {
        Enumeration keys = filter.keys();
        while( keys.hasMoreElements() ){
          String key = (String)keys.nextElement();
          if( filter.get(key) instanceof String ){
            newContext.put(key, filter.get(key));
          }
        }
      }
      catch (JSONException e)
      {
View Full Code Here

    private static boolean parse(XMLTokener x, JSONObject context,
                                 String name) throws JSONException {
        char       c;
        int        i;
        String     n;
        JSONObject o = null;
        String     s;
        Object     t;

// Test for and skip past these forms:
//      <!-- ... -->
//      <!   ...   >
//      <![  ... ]]>
//      <?   ...  ?>
// Report errors for these forms:
//      <>
//      <=
//      <<

        t = x.nextToken();

// <!

        if (t == BANG) {
            c = x.next();
            if (c == '-') {
                if (x.next() == '-') {
                    x.skipPast("-->");
                    return false;
                }
                x.back();
            } else if (c == '[') {
                t = x.nextToken();
                if (t.equals("CDATA")) {
                    if (x.next() == '[') {
                        s = x.nextCDATA();
                        if (s.length() > 0) {
                            context.accumulate("content", s);
                        }
                        return false;
                    }
                }
                throw x.syntaxError("Expected 'CDATA['");
            }
            i = 1;
            do {
                t = x.nextMeta();
                if (t == null) {
                    throw x.syntaxError("Missing '>' after '<!'.");
                } else if (t == LT) {
                    i += 1;
                } else if (t == GT) {
                    i -= 1;
                }
            } while (i > 0);
            return false;
        } else if (t == QUEST) {

// <?

            x.skipPast("?>");
            return false;
        } else if (t == SLASH) {

// Close tag </

            if (name == null || !x.nextToken().equals(name)) {
                throw x.syntaxError("Mismatched close tag");
            }
            if (x.nextToken() != GT) {
                throw x.syntaxError("Misshaped close tag");
            }
            return true;

        } else if (t instanceof Character) {
            throw x.syntaxError("Misshaped tag");

// Open tag <

        } else {
            n = (String)t;
            t = null;
            o = new JSONObject();
            for (;;) {
                if (t == null) {
                    t = x.nextToken();
                }

// attribute = value

                if (t instanceof String) {
                    s = (String)t;
                    t = x.nextToken();
                    if (t == EQ) {
                        t = x.nextToken();
                        if (!(t instanceof String)) {
                            throw x.syntaxError("Missing value");
                        }
                        o.accumulate(s, t);
                        t = null;
                    } else {
                        o.accumulate(s, "");
                    }

// Empty tag <.../>

                } else if (t == SLASH) {
                    if (x.nextToken() != GT) {
                        throw x.syntaxError("Misshaped tag");
                    }
                    context.accumulate(n, o);
                    return false;

// Content, between <...> and </...>

                } else if (t == GT) {
                    for (;;) {
                        t = x.nextContent();
                        if (t == null) {
                            if (name != null) {
                                throw x.syntaxError("Unclosed tag " + name);
                            }
                            return false;
                        } else if (t instanceof String) {
                            s = (String)t;
                            if (s.length() > 0) {
                                o.accumulate("content", s);
                            }

// Nested element

                        } else if (t == LT) {
                            if (parse(x, o, n)) {
                                if (o.length() == 0) {
                                    context.accumulate(n, "");
                                } else if (o.length() == 1 &&
                                       o.opt("content") != null) {
                                    context.accumulate(n, o.opt("content"));
                                } else {
                                    context.accumulate(n, o);
                                }
                                return false;
                            }
View Full Code Here

     * @param string The source string.
     * @return A JSONObject containing the structured data from the XML string.
     * @throws JSONException
     */
    public static JSONObject toJSONObject(String string) throws JSONException {
        JSONObject o = new JSONObject();
        XMLTokener x = new XMLTokener(string);
        while (x.more()) {
            x.skipPast("<");
            parse(x, o, null);
        }
View Full Code Here

    public static String toString(Object o, String tagName)
            throws JSONException {
        StringBuffer b = new StringBuffer();
        int          i;
        JSONArray    ja;
        JSONObject   jo;
        String       k;
        Enumeration  keys;
        int          len;
        String       s;
        Object       v;
        if (o instanceof JSONObject) {

// Emit <tagName>

            if (tagName != null) {
                b.append('<');
                b.append(tagName);
                b.append('>');
            }

// Loop thru the keys.

            jo = (JSONObject)o;
            keys = jo.keys();
            while (keys.hasMoreElements()) {
                k = keys.nextElement().toString();
                v = jo.get(k);
                if (v instanceof String) {
                    s = (String)v;
                } else {
                    s = null;
                }
View Full Code Here

  public static double distance(double x, double y) {
    return Math.sqrt(x * x + y * y);
  }

  public static JSONObject toJSONObject(Hashtable hashtable) throws JSONException {
    JSONObject json = new JSONObject();
    Enumeration e = hashtable.keys();
    while (e.hasMoreElements()) {
      String key = ((String) e.nextElement());
      json.accumulate(key, hashtable.get(key));
    }
    return json;

  }
View Full Code Here

    return contents;
  }

  public static JSONObject fromJSONFile(String filename) {
    try {
      return new JSONObject(new JSONTokener(getFileContents(filename)));
    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }
  }
View Full Code Here

    public static double distance(double x, double y) {
        return Math.sqrt(x * x + y * y);
    }

    public static JSONObject toJSONObject(Hashtable hashtable) throws JSONException {
        JSONObject json = new JSONObject();
        Enumeration e = hashtable.keys();
        while (e.hasMoreElements()) {
            String key = ((String) e.nextElement());
            json.accumulate(key, hashtable.get(key));
        }
        return json;

    }
View Full Code Here

   * When data arrives on the socket, we parse it to JSON and then send the
   * resulting data structure to be interpreted for use.
   */
  public void dataRecieved(SocketEvent e) {
    try {
      JSONObject command = new JSONObject(e.getData());
      // parsing JSON can throw json exceptions.
      doCommand(command);
    } catch (Exception e1) {
      e1.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of org.json.me.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.