Example usage for org.json.simple JSONObject get

List of usage examples for org.json.simple JSONObject get

Introduction

In this page you can find the example usage for org.json.simple JSONObject get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.portfolio.data.utils.PostForm.java

public static boolean updateResource(String sessionid, String backend, String uuid, String lang, String json)
        throws Exception {
    /// Parse and create xml from JSON
    JSONObject files = (JSONObject) JSONValue.parse(json);
    JSONArray array = (JSONArray) files.get("files");

    if ("".equals(lang) || lang == null)
        lang = "fr";

    JSONObject obj = (JSONObject) array.get(0);
    String ressource = "";
    String attLang = " lang=\"" + lang + "\"";
    ressource += "<asmResource>" + "<filename" + attLang + ">" + obj.get("name") + "</filename>" + // filename
            "<size" + attLang + ">" + obj.get("size") + "</size>" + "<type" + attLang + ">" + obj.get("type")
            + "</type>" +
            //      obj.get("url");   // Backend source, when there is multiple backend
            "<fileid" + attLang + ">" + obj.get("fileid") + "</fileid>" + "</asmResource>";

    /// Send data to resource
    /// Server + "/resources/resource/file/" + uuid +"?lang="+ lang
    CloseableHttpClient httpclient = HttpClients.createDefault();
    try {//from w ww  . j a v a2s.  c  o  m
        HttpPut put = new HttpPut("http://" + backend + "/rest/api/resources/resource/" + uuid);
        put.setHeader("Cookie", "JSESSIONID=" + sessionid); // So that the receiving servlet allow us

        StringEntity se = new StringEntity(ressource);
        se.setContentEncoding("application/xml");
        put.setEntity(se);

        CloseableHttpResponse response = httpclient.execute(put);

        try {
            HttpEntity resEntity = response.getEntity();
        } finally {
            response.close();
        }
    } finally {
        httpclient.close();
    }

    return false;
}

From source file:com.serena.rlc.provider.jenkins.domain.JobParameter.java

public static List<JobParameter> parse(String options) {
    List<JobParameter> list = new ArrayList<>();
    JSONParser parser = new JSONParser();
    try {//  w  ww . j  a v a  2 s.c  om
        Object parsedObject = parser.parse(options);
        JSONArray array = (JSONArray) ((JSONObject) parsedObject).get("actions");
        for (Object action : array) {
            JSONArray paramDefs = (JSONArray) ((JSONObject) action).get("parameterDefinitions");

            if (paramDefs != null && paramDefs.size() > 0) {
                for (Object param : paramDefs) {
                    JobParameter obj = new JobParameter();
                    JSONObject jsonObject = (JSONObject) param;

                    obj.setName((String) jsonObject.get("name"));
                    obj.setType((String) jsonObject.get("type"));

                    try {
                        JSONObject deafultValueJsonObject = (JSONObject) jsonObject
                                .get("defaultParameterValue");
                        obj.setDefaultValue((String) deafultValueJsonObject.get("value"));
                    } catch (Exception ex) {
                    }

                    list.add(obj);
                }
            }
        }
    } catch (ParseException e) {
        logger.error("Error while parsing input JSON - " + options, e);
    }

    return list;
}

From source file:de.hstsoft.sdeep.model.TerrainNode.java

public static TerrainNode parseNode(String key, JSONObject node) {

    TerrainNode terrainNode = new TerrainNode(key);

    terrainNode.name = node.get(NAME).toString();
    terrainNode.biome = node.get(BIOME).toString();
    terrainNode.fullyGernerated = Utils.toBool(node.get(FULLY_GENERATED).toString());
    terrainNode.heightValue = Utils.toInt(node.get(HEIGHT_VALUE).toString());
    terrainNode.seedEffect = Utils.toInt(node.get(SEED_EFFECT).toString());

    JSONObject position = (JSONObject) node.get(POSITION);
    terrainNode.position = Position.parseVector(position);

    JSONObject positionOffset = (JSONObject) node.get(POSITION_OFFSET);
    terrainNode.positionOffset = Position.parseVector(positionOffset);

    JSONObject objects = (JSONObject) node.get(OBJECTS);

    if (objects != null) {
        Iterator<?> iter = objects.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<?, ?> entry = (Map.Entry<?, ?>) iter.next();

            JSONObject childJson = (JSONObject) objects.get(entry.getKey().toString());
            GameObject child = GameObject.parse(childJson);
            terrainNode.children.add(child);
        }// w w w . j  a v a  2  s. co  m
    }
    Collections.sort(terrainNode.children, new GameObjectComparator());
    return terrainNode;
}

From source file:iracing.webapi.LicenseLevelParser.java

static List<LicenseLevel> parse(String json) {
    //var licenseLevels = extractJSON('{"22":{"groupId":6,"name":"Pro+%282.0%29","id":22,"colorIndex":240},"23":{"groupId":6,"name":"Pro+%283.0%29","id":23,"colorIndex":240},"24":{"groupId":6,"name":"Pro+%284.0%29","id":24,"colorIndex":240},"25":{"groupId":7,"name":"Pro%2FWC+%281.0%29","id":25,"colorIndex":240},"26":{"groupId":7,"name":"Pro%2FWC+%282.0%29","id":26,"colorIndex":240},"27":{"groupId":7,"name":"Pro%2FWC+%283.0%29","id":27,"colorIndex":240},"28":{"groupId":7,"name":"Pro%2FWC+%284.0%29","id":28,"colorIndex":240},"10":{"groupId":3,"name":"Class+C+%282.0%29","id":10,"colorIndex":116},"11":{"groupId":3,"name":"Class+C+%283.0%29","id":11,"colorIndex":116},"12":{"groupId":3,"name":"Class+C+%284.0%29","id":12,"colorIndex":116},"13":{"groupId":4,"name":"Class+B+%281.0%29","id":13,"colorIndex":86},"14":{"groupId":4,"name":"Class+B+%282.0%29","id":14,"colorIndex":86},"15":{"groupId":4,"name":"Class+B+%283.0%29","id":15,"colorIndex":86},"16":{"groupId":4,"name":"Class+B+%284.0%29","id":16,"colorIndex":86},"17":{"groupId":5,"name":"Class+A+%281.0%29","id":17,"colorIndex":107},"18":{"groupId":5,"name":"Class+A+%282.0%29","id":18,"colorIndex":107},"19":{"groupId":5,"name":"Class+A+%283.0%29","id":19,"colorIndex":107},"1":{"groupId":1,"name":"Rookie+%281.0%29","id":1,"colorIndex":112},"2":{"groupId":1,"name":"Rookie+%282.0%29","id":2,"colorIndex":112},"3":{"groupId":1,"name":"Rookie+%283.0%29","id":3,"colorIndex":112},"4":{"groupId":1,"name":"Rookie+%284.0%29","id":4,"colorIndex":112},"5":{"groupId":2,"name":"Class+D+%281.0%29","id":5,"colorIndex":130},"6":{"groupId":2,"name":"Class+D+%282.0%29","id":6,"colorIndex":130},"7":{"groupId":2,"name":"Class+D+%283.0%29","id":7,"colorIndex":130},"8":{"groupId":2,"name":"Class+D+%284.0%29","id":8,"colorIndex":130},"9":{"groupId":3,"name":"Class+C+%281.0%29","id":9,"colorIndex":116},"20":{"groupId":5,"name":"Class+A+%284.0%29","id":20,"colorIndex":107},"21":{"groupId":6,"name":"Pro+%281.0%29","id":21,"colorIndex":240}}');
    JSONParser parser = new JSONParser();
    List<LicenseLevel> output = null;
    try {/*from ww  w.  jav a  2s  .  com*/
        JSONObject root = (JSONObject) parser.parse(json);
        output = new ArrayList<LicenseLevel>();
        for (Object key : root.keySet()) {
            LicenseLevel ll = new LicenseLevel();
            JSONObject o = (JSONObject) root.get(key);
            ll.setLicenseGroupId(getInt(o, "groupId"));
            ll.setName(getString(o, "name", true));
            ll.setId(getInt(o, "id"));
            output.add(ll);
        }
    } catch (ParseException ex) {
        Logger.getLogger(LicenseLevelParser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return output;
}

From source file:com.stratio.deep.aerospike.AerospikeJavaRDDFT.java

/**
 * Imports dataset./*  ww w. ja  v  a 2s.  c o m*/
 *
 * @throws java.io.IOException
 */
private static void dataSetImport() throws IOException, ParseException {
    URL url = Resources.getResource(DATA_SET_NAME);
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(new FileReader(url.getFile()));
    JSONObject jsonObject = (JSONObject) obj;

    String id = (String) jsonObject.get("id");
    JSONObject metadata = (JSONObject) jsonObject.get("metadata");
    JSONArray cantos = (JSONArray) jsonObject.get("cantos");

    Key key = new Key(NAMESPACE_ENTITY, SET_NAME, id);
    Bin binId = new Bin("id", id);
    Bin binMetadata = new Bin("metadata", metadata);
    Bin binCantos = new Bin("cantos", cantos);
    aerospike.put(null, key, binId, binMetadata, binCantos);
    aerospike.createIndex(null, NAMESPACE_ENTITY, SET_NAME, "id_idx", "id", IndexType.STRING);

    Key key2 = new Key(NAMESPACE_CELL, SET_NAME, 3);
    Bin bin_id = new Bin("_id", "3");
    Bin bin_number = new Bin("number", 3);
    Bin bin_text = new Bin("message", "new message test");
    aerospike.put(null, key2, bin_id, bin_number, bin_text);
    aerospike.createIndex(null, NAMESPACE_CELL, SET_NAME, "num_idx", "number", IndexType.NUMERIC);
    aerospike.createIndex(null, NAMESPACE_CELL, SET_NAME, "_id_idx", "_id", IndexType.STRING);
}

From source file:ly.stealth.punxsutawney.Marathon.java

private static JSONObject getApp(String app) throws IOException {
    JSONObject response = sendRequest("/v2/apps/" + app, "GET", null);
    return response != null ? (JSONObject) response.get("app") : null;
}

From source file:me.fromgate.messagecommander.PLListener.java

private static String jsonToString(JSONObject source) {
    String result = "";
    for (Object key : source.keySet()) {
        Object value = source.get(key);
        if (value instanceof String) {
            if ((key instanceof String) && (!((String) key).equalsIgnoreCase("text")))
                continue;
            result = result + (String) value;
        } else if (value instanceof JSONObject) {
            result = result + jsonToString((JSONObject) value);
        } else if (value instanceof JSONArray) {
            result = result + jsonToString((JSONArray) value);
        }//from   www .j  a  v a 2  s .  c om
    }
    return result;
}

From source file:br.net.fabiozumbi12.RedProtect.hooks.MojangUUIDs.java

public static String getName(String UUID) {
    try {/*from   www.j  a v  a  2s. com*/
        URL url = new URL("https://api.mojang.com/user/profiles/" + UUID.replaceAll("-", "") + "/names");
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String line = in.readLine();
        if (line == null) {
            return null;
        }
        JSONArray array = (JSONArray) new JSONParser().parse(line);
        HashMap<Long, String> names = new HashMap<Long, String>();
        String name = "";
        for (Object profile : array) {
            JSONObject jsonProfile = (JSONObject) profile;
            if (jsonProfile.containsKey("changedToAt")) {
                names.put((long) jsonProfile.get("changedToAt"), (String) jsonProfile.get("name"));
                continue;
            }
            name = (String) jsonProfile.get("name");
        }
        if (!names.isEmpty()) {
            Long key = Collections.max(names.keySet());
            return names.get(key);
        } else {
            return name;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:ch.newscron.encryption.Encryption.java

/**
 * Given a JSONObject, it is checked if it is a good JSONObject depending what data we need.
 * @param obj is the JSONObject to check
 * @return true if the JSONObject is a good one, false otherwise
 *///from  ww  w  . jav  a  2 s. co  m
public static boolean checkDataValidity(JSONObject obj) {
    return obj != null && obj.size() == 4 && obj.get("custID") != null
            && !((String) obj.get("custID")).isEmpty() && obj.get("rew1") != null
            && !((String) obj.get("rew1")).isEmpty() && obj.get("rew2") != null
            && !((String) obj.get("rew2")).isEmpty() && obj.get("val") != null
            && !((String) obj.get("val")).isEmpty();
}

From source file:biomine.bmvis2.pipeline.GraphOperationSerializer.java

public static GraphOperation fromJSON(JSONObject o) throws GraphOperationSerializationException {

    try {//from  w w  w.  j a  v  a  2  s .c  o m
        String className = o.get("class").toString();

        Class cl = GraphOperationSerializer.class.getClassLoader().loadClass(className);

        GraphOperation ret = (GraphOperation) cl.newInstance();
        JSONObject retJSON = (JSONObject) o.get("object");
        ret.fromJSON(retJSON);
        return ret;
    } catch (Exception e) {
        throw new GraphOperationSerializationException(e);
    }
}