Example usage for org.json.simple JSONArray add

List of usage examples for org.json.simple JSONArray add

Introduction

In this page you can find the example usage for org.json.simple JSONArray add.

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:cc.sferalabs.libs.telegram.bot.api.types.ReplyKeyboardMarkup.java

/**
 * @param keyboard/*from  w ww .java 2s .c  o  m*/
 * @return
 */
@SuppressWarnings("unchecked")
private static JSONArray toJsonArray(String[][] keyboard) {
    JSONArray matrix = new JSONArray();
    for (String[] line : keyboard) {
        JSONArray array = new JSONArray();
        array.addAll(Arrays.asList(line));
        matrix.add(array);
    }
    return matrix;
}

From source file:cpd3314.buildit12.CPD3314BuildIt12.java

/**
 * Build a sample method that saves a handful of car instances as Serialized
 * objects, and as JSON objects.//from   w w  w  . jav  a2  s.co  m
 */
public static void doBuildIt2Output() {
    Car[] cars = { new Car("Honda", "Civic", 2001), new Car("Buick", "LeSabre", 2003),
            new Car("Toyota", "Camry", 2005) };

    // Saves as Serialized Objects
    try {
        FileOutputStream objFile = new FileOutputStream("cars.obj");
        ObjectOutputStream objStream = new ObjectOutputStream(objFile);

        for (Car car : cars) {
            objStream.writeObject(car);
        }

        objStream.close();
        objFile.close();
    } catch (IOException ex) {
        Logger.getLogger(CPD3314BuildIt12.class.getName()).log(Level.SEVERE, null, ex);
    }

    // Saves as JSONObject
    try {
        PrintWriter jsonStream = new PrintWriter("cars.json");

        JSONArray arr = new JSONArray();
        for (Car car : cars) {
            arr.add(car.toJSON());
        }

        JSONObject json = new JSONObject();
        json.put("cars", arr);

        jsonStream.println(json.toJSONString());

        jsonStream.close();
    } catch (IOException ex) {
        Logger.getLogger(CPD3314BuildIt12.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:mysynopsis.SystemInitializer.java

private static void setDefault() throws IOException {
    JSONObject bio = new JSONObject();
    bio.put("Name", "");
    bio.put("Initial", "");
    bio.put("Bio",
            "<p><font face=\"Arial\" size=\"4\"><b>Biography goes here</b></font></p><p><br></p><p></p><p><font face=\"Segoe UI\" size=\"4\"><br></font></p>");
    bio.put("Designation", "");
    bio.put("Department", "");
    bio.put("University", "");
    bio.put("University_Address", "");
    bio.put("Office", "");
    bio.put("Ohours", "");
    bio.put("Phone", "");
    bio.put("Email", "");
    bio.put("Resume_Link", "");
    bio.put("Educational",
            "<p><font face=\"Arial\" size=\"4\"><b>Educational Information</b></font></p><p><br></p><p></p><p><font face=\"Segoe UI\" size=\"4\"><br></font></p>");
    bio.put("Professional",
            "<p><font face=\"Arial\" size=\"4\"><b>Professional Experience</b></font></p><p><br></p><p></p><p><font face=\"Segoe UI\" size=\"4\"><br></font></p>");
    bio.put("Awards",
            "<p><font face=\"Arial\" size=\"4\"><b>Awards</b></font></p><p><br></p><p></p><p><font face=\"Segoe UI\" size=\"4\"><br></font></p>");

    bio.put("Image_Ext", "png");
    bio.put("Image_String",
            "iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAKxklEQVR42u1de2wcRx0eQEAqQQVCAhFaSiv+QfwBqQoECAgJCbUChCoKCJXm2QYngdA0Aadp1IY4zbNJaePWcR7Ow44fiRO/HdmxYyf3ct2QPpI4e3uk0JBU/EMLTbx7O7vsMt+2xCFOfA/v7s3szk/65Lvz3t3sfDczv9f8hoRBXhqxP5XKmN9LpK35CdVcm1RpA3s8kExbp9njt+IK/XdSoTr7+x8Aj/Ga+z/Veh3Xssf1eG88bT2Cz8JnEinBS7dqfzSept9JqNbyhGK1M2IuJVXL8QNxlV5k5Lex7ypPKXQGvptI8V7i5+yprJMXJhWrg4280VzE+Ej4FfyoUqq14PiI/VkipXiJvel80iVVtU4wUm10ME9Am+KKNcgelw381fkEkZJbHMf5QCJDv5VM031YJ7khNDfZGhvde2MqnU6kjJcDjvOhZMb6GRuxQ+gwoaFYybhq/hT3RKIubMR+MKVYv0iq5jl0TpiQUMyzTCt/APdIoiisA77PTJTX0Bkhxyswu0hUZEix72Q33cLgRAqK1Zx4w74j3Ousai0ZM3OiB9fM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ik9iDiAYMtnMjW+TSQg06uZivhguvFlVksB80DRU7FRN68lkJfGGfUcxseJl9XJqLsD7VdxJ4Kp9G/FAkLO1uEB/cuRJKxAF28gI73p6xHshzo/KXrn2FgiUayzIqeGaRV5KLO3chVOn82nA2jZp8xYIxLnzTsfBskl8ENTUmplPI55okuuvT9Xz4NP+JfFLYG8hYjFxI6TtWwTQZ7nJVcwq4rMgZjwFp05LgoMlGCfCIvuVBCHDGft2lH6QBAdDMLYW4eAyEqQkM8bdsI8lwX4TTC/H0sZXSCkkpZj3MZKpJNgfgtG3cdX8ASmlJFTzAaRqSoI9JlihFlNo7yc8CGvQgyBZEuwNwSDXNYd4EmSBYEqRBE+KYEzLBjcjd7ziZd4LxUsSXCzB9LK75vIsCdWY9niDlo06YYWivFHTXW1ZBHlx0Jj2WK12Oeqk5YtHa7V3n+0xvkpEkueG7FtXHNRGok5eLqw8oJ2uHHA+RkSV9e3G8/OqR+2oE3k9Ht4+am/sMraQMMifuukMNmX/K+qkvg9ku7y9uZdOJ2ESJA1UtOhN86qv2FEetRWt+n43WB9W2dpL7ynfr1+IoBn0t8oBKFIRkWe69EW/q9WuhJ3YJfu0y1s69fkkioIEgnWt+vrFezU9bMQu3qNpGzr0NbhHEnXB+ry+XX96SQgUsaV12jsb2vXV7jorZbw806nPXtmkpedWjwpD6rzto86KRk3ZcsR4iEjJT57rtm9b00L3MPPq7VkcbjlFm5bVav9c10ZrtvbaU4mU4oWNjC+zk1D2lDdkL5XSzMJ3lzfol0DqC53ZLxEp3ktT0r5lc7c+b/VhrbO8Ub+0YOcVy7/qOaPmH+qzFyuatY5NXfqc3QPOFCIleNnUo9+5sUNfUNGa3b2qWY+taBw9j6n9t0yTxQ8ADoa51e606gKP8Rr+h2twLd6D965ho3NTOy1bd0T/AgmB/Bd/W0C3K+5ULAAAAABJRU5ErkJggg==");

    // JSONArray education = new JSONArray();

    /*for(int i=0;i<8;i++) {
            // www.  j a v  a2s  . com
    education.add("");
    }
    bio.put("Education", education);*/

    JSONArray ftpinfo = new JSONArray();

    ftpinfo.add("");
    ftpinfo.add("");
    ftpinfo.add("");

    bio.put("Server_Information", ftpinfo);

    /* JSONArray professional = new JSONArray();
    professional.add("Profession 1: ");
    professional.add("Profession 2: ");
    bio.put("Professional Experience:", professional);
            
    JSONArray awards = new JSONArray();
    awards.add("Award 1: ");
    awards.add("Award 2: ");
    bio.put("Honors & Awards:", awards);*/

    try (FileWriter file = new FileWriter("data.json")) {

        file.write(bio.toJSONString());
    } catch (IOException e) {

        JOptionPane.showMessageDialog(null,
                "Can't Create Data.json File. Please Check Your Directory Permission");
    }
}

From source file:naftoreiclag.villagefive.util.json.JSONUtil.java

public static <SomeJSONThingy extends JSONThingy> JSONArray encodeList(List<SomeJSONThingy> list) {
    JSONArray conv = new JSONArray();

    for (int i = 0; i < list.size(); ++i) {
        SomeJSONThingy thing = list.get(i);

        thing.setJsonIndex(i);//from  w w w. ja v  a2  s. co m
        conv.add(thing);
    }

    return conv;
}

From source file:br.bireme.mlts.utils.Document2JSON.java

public static JSONObject getJSON(final Map<String, List<Fieldable>> map) {
    if (map == null) {
        throw new NullPointerException("map");
    }/*from   w ww.  j a  va  2  s.c o m*/

    final JSONObject jobj = new JSONObject();

    for (Map.Entry<String, List<Fieldable>> entry : map.entrySet()) {
        final String key = entry.getKey();
        final List<Fieldable> value = entry.getValue();
        final boolean multivalue = value.size() > 1;

        if (multivalue) {
            final JSONArray array = new JSONArray();
            jobj.put(key, array);
            for (Fieldable fld : value) {
                array.add(getObject(fld));
            }
        } else {
            jobj.put(key, getObject(value.get(0)));
        }
    }
    return jobj;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.DomainObjectJSONSerializer.java

public static JSONObject getDomainObject(DomainObject obj) throws SecurityException, NoSuchMethodException,
        IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    final JSONObject jsonObject = new JSONObject();
    final Class<? extends DomainObject> clazz = obj.getClass();
    final String objClassName = clazz.getName();

    jsonObject.put("externalId", obj.getExternalId());
    jsonObject.put("className", objClassName);
    final DomainClass domainClass = getDomainClass(objClassName);
    if (domainClass == null) {
        return jsonObject;
    }/*from w  ww  .  j  a v a 2s . c om*/
    for (Slot slot : getAllSlots(domainClass)) {
        final String slotName = slot.getName();
        final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName));
        final Object result = method.invoke(obj);
        jsonObject.put(slotName, result == null ? null : result.toString());
    }

    for (Role roleSlot : getAllRoleSlots(domainClass)) {
        final String slotName = roleSlot.getName();
        if (roleSlot.getMultiplicityUpper() == 1) {
            final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName));
            final AbstractDomainObject singleRelationObj = (AbstractDomainObject) method.invoke(obj);
            final JSONArray oneRelation = new JSONArray();
            if (singleRelationObj != null) {
                oneRelation.add(singleRelationObj.getExternalId());
            }
            jsonObject.put(slotName, oneRelation);
        } else {
            final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName) + "Set");
            final Set<? extends AbstractDomainObject> result = (Set<? extends AbstractDomainObject>) method
                    .invoke(obj);
            jsonObject.put(slotName, serializeRelation(result));
        }

    }

    return jsonObject;
}

From source file:com.cloudera.hoop.fs.FSUtils.java

/**
 * Converts a Hadoop <code>FileStatus</code> array into a JSON array
 * object. It replaces the <code>SCHEME://HOST:PORT</code> of the path
 * with the  specified URL./*  w  w w. j  ava 2  s.co m*/
 * <p/>
 * @param status Hadoop file status array.
 * @param hoopBaseUrl base URL to replace the
 * <code>SCHEME://HOST:PORT</code> in the file status.
 * @return The JSON representation of the file status array.
 */
@SuppressWarnings("unchecked")
public static JSONArray fileStatusToJSON(FileStatus[] status, String hoopBaseUrl) {
    JSONArray json = new JSONArray();
    if (status != null) {
        for (FileStatus s : status) {
            json.add(fileStatusToJSON(s, hoopBaseUrl));
        }
    }
    return json;
}

From source file:com.opensoc.json.serialization.JSONDecoderHelper.java

@SuppressWarnings("unchecked")
public static JSONArray getArray(DataInputStream data) throws IOException {
    // TODO Auto-generated method stub
    JSONArray output = new JSONArray();
    int size = data.readInt();

    for (int i = 0; i < size; i++) {
        Object value = getObject(data);
        output.add(value);
    }//  w  w w .j  a v a  2s  .  c  om

    return output;
}

From source file:it.cnr.isti.thematrix.scripting.sys.DatasetSchema.java

/**
 * Converts the argument schema into a JSON String
 * @param schema/*from  w ww. j  ava 2  s .com*/
 * @return he argument schema into a JSON String
 */
public static String toJSON(DatasetSchema schema) {
    JSONArray list = new JSONArray();
    list.add(schema.name);
    for (Symbol<?> s : schema.attributes()) {
        JSONObject obj = new JSONObject();
        obj.put("name", s.name);
        obj.put("type", s.type.toString());
        list.add(obj);
    }

    return list.toJSONString();
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.registry.RegistryPersistence.java

@SuppressWarnings("unchecked")
public static void storeRegistry(File registryFile, Map<String, IRegistrationData> registrationData)
        throws IOException {
    synchronized (lock) {
        JSONArray obj = new JSONArray();
        for (Entry<String, IRegistrationData> entry : registrationData.entrySet()) {
            IRegistrationData rd = entry.getValue();
            obj.add(rd);
        }//www. jav a 2 s.co  m

        PrintWriter pw = new PrintWriter(registryFile);
        pw.print(obj.toString());
        pw.close();
        LOG.info("Registry successfully saved to file " + registryFile);
    }
}