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.serena.rlc.provider.jira.domain.Project.java

public static List<Project> parse(String options) {
    List<Project> list = new ArrayList<>();
    JSONParser parser = new JSONParser();
    try {//  ww w.  jav  a  2  s  .  c  o m
        Object parsedObject = parser.parse(options);
        JSONArray array = (JSONArray) parsedObject;
        for (Object object : array) {
            Project obj = new Project();
            JSONObject jsonObject = (JSONObject) object;
            obj.setId((String) jsonObject.get("id"));
            obj.setName((String) jsonObject.get("name"));
            obj.setKey((String) jsonObject.get("key"));
            list.add(obj);
        }
    } catch (ParseException e) {
        logger.error("Error while parsing input JSON - " + options, e);
    }

    return list;
}

From source file:fr.free.movierenamer.utils.JSONUtils.java

public static JSONObject selectFirstObject(final JSONObject rootObject) {
    try {//from  w w  w.  jav a2 s. com
        JSONObject toSearch = rootObject;
        return (JSONObject) toSearch.get(toSearch.keySet().iterator().next());
    } catch (Exception e) {
        //
    }
    return null;
}

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

public static Atmosphere parse(JSONObject json) {
    Atmosphere atmosphere = new Atmosphere();

    atmosphere.timeOfDay = Utils.toFloat((String) json.get(TIME_OF_DAY));
    atmosphere.year = Utils.toInt(json.get(YEAR).toString());
    atmosphere.month = Utils.toInt(json.get(MONTH).toString());
    atmosphere.day = Utils.toInt(json.get(DAY).toString());
    atmosphere.daysElapsed = Utils.toInt(json.get(DAYS_ELAPSED).toString());

    return atmosphere;
}

From source file:manager.GameElement.java

public static void fromJSON(JSONObject json) {
    level = Integer.valueOf((String) json.get("level"));
    experience = Integer.valueOf((String) json.get("experience"));
    streak = (int) Integer.valueOf((String) json.get("streak"));
}

From source file:com.facebook.tsdb.tsdash.server.model.MetricQuery.java

public static MetricQuery fromJSONObject(JSONObject src) {
    MetricQuery newQuery = new MetricQuery();
    newQuery.name = (String) src.get("name");
    if (src.get("rate") != null) {
        newQuery.rate = (Boolean) src.get("rate");
    }// w w  w  .  j  a v  a 2 s.  com
    newQuery.tags = decodeTags((JSONObject) src.get("tags"));
    newQuery.aggregator = (String) src.get("aggregator");
    newQuery.orders = decodeArray((JSONArray) src.get("orders"));
    newQuery.dissolveTags = decodeArray((JSONArray) src.get("dissolveTags"));
    return newQuery;
}

From source file:cz.mgn.mediservice.rest.Loader.java

public static ArrayList<Drug> loadDrugs(int pharmacyId) {
    ArrayList<Drug> drugs = new ArrayList<Drug>();

    JSONArray json = (JSONArray) loadJson();
    for (Object item : json) {
        JSONObject drugJson = (JSONObject) item;

        int id = Integer.parseInt((String) drugJson.get("id"));
        String name = (String) drugJson.get("name");
        String description = (String) drugJson.get("description");
        float price = Float.parseFloat((String) drugJson.get("price"));

        Drug drug = new Drug(id, name, description, price);
        drugs.add(drug);/*from  ww  w  .  ja v a2s. c  o m*/
    }

    return drugs;
}

From source file:manager.computerVisionManager.java

private static void getJson(String path) {
    System.out.println("Get Description from https://westus.api.cognitive.microsoft.com/vision/v1.0/describe");
    try {/*w  w w  . j a  va2 s .  c o m*/
        URIBuilder builder = new URIBuilder("https://westus.api.cognitive.microsoft.com/vision/v1.0/describe");
        builder.setParameter("maxCandidates", "1");
        URI uri = builder.build();
        HttpPost request = new HttpPost(uri);
        request.setHeader("Content-Type", "application/json");
        request.setHeader("Ocp-Apim-Subscription-Key", "d7f6ef12e41c4f8c8e72d12a890fa703");
        // Request body
        StringEntity reqEntity = new StringEntity("{\"url\":\"" + path + "\"}");
        System.out.println("Request String: " + reqEntity.toString());
        request.setEntity(reqEntity);
        HttpResponse response = httpclient.execute(request);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String respuesta = EntityUtils.toString(entity);
            JSONParser lector = new JSONParser();
            StringReader SR = new StringReader(respuesta);
            try {
                JSONObject temp = (JSONObject) lector.parse(SR);
                json = (JSONObject) temp.get("description");
            } catch (org.json.simple.parser.ParseException e) {
                System.err.println(e.getMessage());
            }
        }
    } catch (IOException | URISyntaxException | ParseException e) {
        System.err.println(e.getMessage());
    }
}

From source file:com.speedment.examples.social.JSONUser.java

public static JSONUser parse(JSONObject user) {
    final JSONUser usr = new JSONUser();
    usr.id = Long.parseLong(user.get("id").toString());
    usr.mail = user.get("mail").toString();
    usr.firstname = mapToString(user, "firstName");
    usr.lastname = mapToString(user, "lastName");
    usr.avatar = Optional.ofNullable(user.get("avatar")).map(Object::toString).filter(s -> !s.isEmpty())
            .map(s -> fromBase64(s)).orElse(null);

    return usr;/*  w  ww .  jav a 2 s .  c  om*/
}

From source file:currencyexchange.JSONCurrency.java

public static ArrayList<CurrencyUnit> getCurrencyUnitsJSON() {
    try {//from  ww w  . j  a v a  2 s .c o  m
        FileReader reader = new FileReader(filePath);

        JSONParser jsonParser = new JSONParser();
        JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);

        JSONArray currencyUnits = (JSONArray) jsonObject.get("units");

        ArrayList<CurrencyUnit> currencies = new ArrayList<CurrencyUnit>();

        Iterator i = currencyUnits.iterator();
        while (i.hasNext()) {
            JSONObject e = (JSONObject) i.next();
            CurrencyUnit currency = new CurrencyUnit((String) e.get("CountryCurrency"),
                    (String) e.get("Units"));

            currencies.add(currency);
        }
        return currencies;

    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (ParseException | NullPointerException ex) {
        ex.printStackTrace();
    }

    return null;
}

From source file:de.keyle.mypet.npc.util.UpdateCheck.java

public static Optional<String> checkForUpdate() {
    try {/*from   ww w. ja  va2 s. co  m*/
        String parameter = "";
        parameter += "build=" + MyPetNpcVersion.getBuild();

        // no data will be saved on the server
        String content = Util.readUrlContent("http://update.mypet-plugin.de/MyPet-NPC?" + parameter);
        JSONParser parser = new JSONParser();
        JSONObject result = (JSONObject) parser.parse(content);

        if (result.containsKey("latest")) {
            return Optional.of(result.get("latest").toString());
        }
    } catch (Exception ignored) {
    }
    return Optional.absent();
}