Package com.granule.json

Examples of com.granule.json.JSONArray


     * *param array An array instance to populate instead of creating a new one.
     *
     * @throws JSONException Thrown if a parse error occurs, such as a malformed JSON array.
     */
    public JSONArray parseArray(boolean ordered, JSONArray array) throws JSONException {
        JSONArray result = null;
        if(array != null){
            result = array;
        } else {
            result = new JSONArray();
        }

        try {
            if (lastToken != Token.TokenBrackL) throw new JSONException("Expecting '[' " + tokenizer.onLineCol());
            lastToken = tokenizer.next();
            while (true) {
                if (lastToken == Token.TokenEOF) throw new JSONException("Unterminated array " + tokenizer.onLineCol());

                /**
                 * End of the array.
                 */
                if (lastToken == Token.TokenBrackR) {
                    lastToken = tokenizer.next();
                    break;
                }

                Object val = parseValue(ordered);
                result.add(val);

                if (lastToken == Token.TokenComma) {
                    lastToken = tokenizer.next();
                } else if (lastToken != Token.TokenBrackR) {
                    throw new JSONException("expecting either ',' or ']' " + tokenizer.onLineCol());
View Full Code Here


        obj.put("id", id);
        obj.put("mime-type", mimeType);
        if (options != null)
            obj.put("options", options);
        if (fragments.size() > 0) {
            JSONArray array = new JSONArray();
            for (FragmentDescriptor fd : fragments) {
                JSONObject o = new JSONObject();
                o.put("type", fd instanceof ExternalFragment ? "file" : "script");
                if (fd instanceof ExternalFragment) o.put("file", ((ExternalFragment) fd).getFilePath());
                else o.put("text", ((InternalFragment) fd).getText());
                array.put(o);
            }
            obj.put("fragments", array);
        }
        if (dependentFragments != null && dependentFragments.size() > 0) {
            JSONArray array = new JSONArray();
            for (FragmentDescriptor fd : dependentFragments) {
                JSONObject o = new JSONObject();
                o.put("file", fd.toString());
                array.put(o);
            }
            obj.put("dependency", array);
        }
        return obj.toString() + "\n";
    }
View Full Code Here

        if (obj.has("options"))
            options = obj.getString("options");
        else options = null;
        fragments = new ArrayList<FragmentDescriptor>();
        if (obj.has("fragments")) {
            JSONArray array = obj.getJSONArray("fragments");
            for (int i = 0; i < array.length(); i++) {
                JSONObject o = (JSONObject) array.get(i);
                FragmentDescriptor fd;
                if (o.getString("type").equals("file")) {
                    fd = new ExternalFragment(o.getString("file"));
                } else {
                    fd = new InternalFragment(o.getString("text"));
                }
                fragments.add(fd);
            }
        }
        dependentFragments.clear();
        if (obj.has("dependency")) {
            JSONArray array = obj.getJSONArray("dependency");
            for (int i = 0; i < array.length(); i++) {
                JSONObject o = (JSONObject) array.get(i);
                FragmentDescriptor fd = new ExternalFragment(o.getString("file"));
                dependentFragments.add(fd);
            }
        }
View Full Code Here

            } else if (JSONArray.class.isAssignableFrom(clazz)) {
                ja = (JSONArray)obj;
            } else if (Map.class.isAssignableFrom(clazz)) {
                ja = new JSONObject((Map)obj);
            } else if (Collection.class.isAssignableFrom(clazz)) {
                ja = new JSONArray((Collection)obj);
            } else if (clazz.isArray()) {
                ja = new JSONArray((Object[])obj);
            }
            else {
                //TODO:  Bean introspection time.
                ja = introspectBean(obj,includeSuperclass, new ArrayList());
            }
View Full Code Here

                                } else if (JSONArray.class.isAssignableFrom(vClazz)) {
                                    ja.put(attr, val);
                                } else if (Map.class.isAssignableFrom(vClazz)) {
                                    ja.put(attr, new JSONObject((Map)val));
                                } else if (Collection.class.isAssignableFrom(vClazz)) {
                                    ja.put(attr, new JSONArray((Collection)obj));
                                } else {
                                    if (val != obj) {
                                        // Try to avoid processing references to itself.
                                        ja.put(attr, introspectBean(val, includeSuperclass, parsedObjects));
                                    }
View Full Code Here

                                                            m = tM;
                                                            if(c != JSONArray.class){
                                                                // Convert it.  Whee.
                                                                List list = (List)c.newInstance();

                                                                JSONArray array = (JSONArray)val;
                                                                for (int j = 0; j < array.length(); j++) {
                                                                    // Convert each type as needed.
                                                                    Object aVal = array.get(j);
                                                                    if(aVal != null){
                                                                        Class aVClazz = aVal.getClass();
                                                                        if(Number.class.isAssignableFrom(aVClazz) ||
                                                                            Boolean.class.isAssignableFrom(aVClazz) ||
                                                                            String.class.isAssignableFrom(aVClazz)) {
View Full Code Here

TOP

Related Classes of com.granule.json.JSONArray

Copyright © 2015 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.