Package org.json.me

Examples of org.json.me.JSONArray


        log("Parsing #records=" + numRecords);

        /*
         * Only unpick the message if it contains a non-zero number of records
         */
        JSONArray recordsArray = new JSONArray();
        result.put(Constants.NDEF_RECORDS, recordsArray);

        if (numRecords > 0) {
            /*
             * Work our way through each record in the message in turn
             */
            for (int j = 0; j < numRecords; ++j) {
                log("parseMessage record #" + j);

                NDEFRecord currentRecord = records[j];
                JSONObject jsonRecord = new JSONObject();
                recordsArray.put(jsonRecord);

                log("Processing NDEF record#=" + j);

                typeNameFormat = currentRecord.getTypeNameFormat();
                record_type = records[j].getType();
View Full Code Here


        toReturn.putOpt(Constants.NDEF_TYPE, record.getType());
        toReturn.put(Constants.NDEF_TYPE_NAME_FORMAT,
                record.getTypeNameFormat());

        byte[] payloadBytes = record.getPayload();
        JSONArray bytePayload = new JSONArray();

        for (int i = 0; i < payloadBytes.length; i++) {
            byte b = payloadBytes[i];
            bytePayload.put(b & 0xff);
        }

        toReturn.put("payload", bytePayload);
        return toReturn;
    }
View Full Code Here

    protected JSONObject parseSmartPoster(NDEFRecord record)
            throws JSONException, IOException {
        log("parseSmartPoster(NDEFRecord)");
        JSONObject toReturn = new JSONObject();
        JSONArray recordsArray = new JSONArray();
        toReturn.put("records", recordsArray);
        // testing

        // if (true)
        // throw new JSONException("Fictitious JSON problem");

        // if(true)
        // throw new
        // UnsupportedEncodingException("Fictitious encoding problem");

        // if(true)
        // throw new BadFormatException("Fictitious format problem");

        // if(true)
        // throw new NFCException("Fictitious NFC problem");

        log("Recognised a Smart Poster Message");
        // try {
        NDEFMessage smartPosterMessage = new NDEFMessage(record.getPayload());
        NDEFRecord[] spRecords = smartPosterMessage.getRecords();
        int numSpRecords = spRecords.length;
        log("Parsing smartposter #records=" + numSpRecords);

        if (numSpRecords > 0) {
            log("Parsing Smart Poster Message");
            for (int k = 0; k < numSpRecords; ++k) {
                log("parseSmartPoster record #" + k);
                JSONObject currentRecordJSON = parseGenericRecord(spRecords[k]);
                recordsArray.put(currentRecordJSON);
                log("Parsing SP record#=" + k);
                byte[] spPayloadBytes = spRecords[k].getPayload();

                int tnf = spRecords[k].getTypeNameFormat();
                String type = spRecords[k].getType();
View Full Code Here

    }

    private JSONArray getOrCreateArray(JSONObject object, String name)
            throws JSONException {
        log("getOrCreateArray(JSONObject,String)");
        JSONArray toReturn = null;
        if (object.has(name)) {
            toReturn = object.getJSONArray(name);
        } else {
            toReturn = new JSONArray();
            object.put(name, toReturn);
        }
        return toReturn;
    }
View Full Code Here

            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)) {
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;
                }

// Emit content in body

                if (k.equals("content")) {
                    if (v instanceof JSONArray) {
                        ja = (JSONArray)v;
                        len = ja.length();
                        for (i = 0; i < len; i += 1) {
                            if (i > 0) {
                                b.append('\n');
                            }
                            b.append(escape(ja.get(i).toString()));
                        }
                    } else {
                        b.append(escape(v.toString()));
                    }

// Emit an array of similar keys

                } else if (v instanceof JSONArray) {
                    ja = (JSONArray)v;
                    len = ja.length();
                    for (i = 0; i < len; i += 1) {
                        b.append(toString(ja.get(i), k));
                    }
                } else if (v.equals("")) {
                    b.append('<');
                    b.append(k);
                    b.append("/>");

// Emit a new tag <k>

                } else {
                    b.append(toString(v, k));
                }
            }
            if (tagName != null) {

// Emit the </tagname> close tag

                b.append("</");
                b.append(tagName);
                b.append('>');
            }
            return b.toString();

// XML does not have good support for arrays. If an array appears in a place
// where XML is lacking, synthesize an <array> element.

        } else if (o instanceof JSONArray) {
            ja = (JSONArray)o;
            len = ja.length();
            for (i = 0; i < len; ++i) {
                b.append(toString(
                    ja.opt(i), (tagName == null) ? "array" : tagName));
            }
            return b.toString();
        } else {
            s = (o == null) ? "null" : escape(o.toString());
            return (tagName == null) ? "\"" + s + "\"" :
View Full Code Here

                    final int p) throws JSONException {
        Object temp;

        final int newParent = tree.addChildNode(p, "Object" + p);

        final JSONArray a = o.names();

        for (int i = 0; i < a.length(); ++i) {
            temp = o.get(a.getString(i));

            if (temp == null || temp.toString().equalsIgnoreCase("null")) {
                continue;
            }
            if (temp instanceof JSONArray) {
                populateTreeArray(tree, (JSONArray) temp, newParent);
            } else if (temp instanceof JSONObject) {
                populateTreeObject(tree, (JSONObject) temp, newParent);
            } else {
                tree.addSiblingNode(newParent, a.getString(i) + ": "
                        + temp.toString());
            }
        }

        return newParent;
View Full Code Here

TOP

Related Classes of org.json.me.JSONArray

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.