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:br.com.RatosDePC.Brpp.Utils.JSONUtils.java

public static void config(String path) throws FileNotFoundException, IOException, ParseException {
    System.out.println("chamado");
    JSONParser parser = new JSONParser();

    Object obj = parser.parse(new FileReader(path + System.getProperty("file.separator") + "lib"
            + System.getProperty("file.separator") + "pt-br.json"));
    JSONObject jsonObject = (JSONObject) obj;
    Keywords = (JSONArray) jsonObject.get("Keywords");
}

From source file:com.modeln.batam.connector.wrapper.Pair.java

public static Pair fromJSON(JSONObject obj) {
    String name = (String) obj.get("name");
    String value = (String) obj.get("value");

    return new Pair(name, value);
}

From source file:Manager.CSMSManager.java

public static List<CSMS> loadFromJson(JSONArray pAryJson) {

    List<CSMS> lstSMS = new ArrayList<>();

    for (Object objJson : pAryJson) {

        JSONObject objInnerObj = (JSONObject) objJson;

        CSMS objSMS = new CSMS(objInnerObj.get("from").toString(), objInnerObj.get("to").toString(),
                objInnerObj.get("msg").toString());

        lstSMS.add(objSMS);/*from   www.  j  ava 2s. c o m*/

    }

    return lstSMS;

}

From source file:com.articulate.sigma.nlp.CorefSubstitutorLargeTest.java

@Parameterized.Parameters(name = "{2}{0}")
public static Collection<Object[]> prepare() {

    return JsonReader.transform("miscellaneous/corefsSubstitution.json", (JSONObject jo) -> {

        String input = (String) jo.get("in");
        String expected = (String) jo.get("out");
        String prefix = "";
        if (Boolean.TRUE.equals(jo.get("failed"))) {
            prefix = " ";
        }/*from   w  ww. java  2 s . c  o  m*/

        return new Object[] { input, expected, prefix };
    });
}

From source file:iracing.webapi.SeasonTimeTrialStandingsParser.java

public static SeasonTimeTrialStandings parse(String json) {
    JSONParser parser = new JSONParser();
    SeasonTimeTrialStandings output = null;
    try {//from w w w  . j av a2 s.  c o m
        JSONObject root = (JSONObject) parser.parse(json);
        Object o = root.get("d");
        if (o instanceof JSONObject) {
            JSONObject d = (JSONObject) o;
            output = new SeasonTimeTrialStandings();
            String s = getString(d, "5");
            output.setApiUserRow(Integer.parseInt(s));
            output.setTotalRecords(getLong(d, "18"));
            JSONArray arrayRoot = (JSONArray) d.get("r");
            List<SeasonTimeTrialStanding> standings = new ArrayList<SeasonTimeTrialStanding>();
            for (int i = 0; i < arrayRoot.size(); i++) {
                JSONObject r = (JSONObject) arrayRoot.get(i);
                SeasonTimeTrialStanding standing = new SeasonTimeTrialStanding();
                standing.setDroppedWeeks(getInt(r, "1"));
                standing.setClubName(getString(r, "2", true));
                o = r.get("3");
                if (o instanceof Double) {
                    standing.setTotalPoints((Double) o);
                } else if (o instanceof Long) {
                    standing.setTotalPoints(Double.parseDouble(String.valueOf(o)));
                }
                standing.setLicenseSubLevel(getString(r, "4"));
                standing.setMaxLicenseLevel(getInt(r, "6"));
                standing.setRank(getInt(r, "7"));
                standing.setDivision(getInt(r, "9"));
                standing.setDriverName(getString(r, "10", true));
                standing.setDriverCustomerId(getLong(r, "12"));
                standing.setTotalStarts(getInt(r, "14"));
                standing.setClubId(getInt(r, "15"));
                standing.setWeeksCounted(getInt(r, "17"));
                standing.setTotalWins(getInt(r, "19"));
                standing.setPosition(getInt(r, "20"));
                standings.add(standing);
            }
            output.setStandings(standings);
        }
    } catch (ParseException ex) {
        Logger.getLogger(SeasonTimeTrialStandingsParser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return output;
}

From source file:com.punyal.blackhole.utils.Parsers.java

public static JSONObject senml2json(String s) {
    JSONObject json, tmp;/* w  w w  .  j av a  2 s  .c o  m*/
    String data;

    json = new JSONObject();
    try {
        tmp = (JSONObject) JSONValue.parse(s);

        // Save base time
        json.put("time", tmp.get("bt"));

        JSONArray slideContent = (JSONArray) tmp.get("e");
        Iterator i = slideContent.iterator();

        while (i.hasNext()) {
            JSONObject slide = (JSONObject) i.next();
            json.put(slide.get("n"), slide.get("v"));
        }
    } catch (NullPointerException e) {
    }
    return json;
}

From source file:net.duckling.falcon.xss.JSONConfig.java

private static void addTags(Whitelist whitelist, JSONObject config) {
    JSONObject whiteListJson = (JSONObject) config.get("whiteList");
    for (String tagname : whiteListJson.keySet()) {
        whitelist.addTags(tagname);// w ww.j av  a 2 s .  co m
        JSONArray attributes = (JSONArray) whiteListJson.get(tagname);
        for (Object attribute : attributes) {
            whitelist.addAttributes(tagname, (String) attribute);
        }
    }
}

From source file:com.articulate.sigma.nlp.TFIDFTest.java

@Parameterized.Parameters(name = "<{0}> {1}")
public static Collection<Object[]> prepare() {
    return JsonReader.transform("QA/json/IRtests.json", (JSONObject jo) -> {
        String fname = (String) jo.get("file");
        String query = (String) jo.get("query");
        String answer = (String) jo.get("answer");
        return new Object[] { fname, query, answer };
    });/*from   w  w w .j  ava2 s .c  o  m*/
}

From source file:iracing.webapi.TimeTrialResultStandingsParser.java

public static TimeTrialResultStandings parse(String json) {
    TimeTrialResultStandings output = null;
    JSONParser parser = new JSONParser();
    try {//ww  w  .j av  a  2s. c  o m
        JSONObject root = (JSONObject) parser.parse(json);
        Object o = root.get("d");
        if (o instanceof JSONObject) {
            JSONObject d = (JSONObject) o;
            output = new TimeTrialResultStandings();
            String s = (String) d.get("3");
            output.setApiUserRow(Integer.parseInt(s));
            output.setTotalRecords(getInt(d, "17"));
            JSONArray arrayRoot = (JSONArray) d.get("r");
            List<TimeTrialResultStanding> standings = new ArrayList<TimeTrialResultStanding>();
            for (int i = 0; i < arrayRoot.size(); i++) {
                JSONObject r = (JSONObject) arrayRoot.get(i);
                TimeTrialResultStanding standing = new TimeTrialResultStanding();
                o = r.get("1");
                if (o instanceof Double) {
                    standing.setPoints((Double) o);
                } else if (o instanceof Long) {
                    standing.setPoints(Double.parseDouble(String.valueOf(o)));
                }
                standing.setLicenseSubLevel(getString(r, "2"));
                standing.setMaxLicenseLevel(getInt(r, "4"));
                standing.setRank(getInt(r, "5"));
                standing.setDivision(getInt(r, "7"));
                standing.setDriverName(getString(r, "8", true));
                standing.setDriverCustomerId(getLong(r, "10"));
                standing.setTotalStarts(getInt(r, "12"));
                standing.setBestTimeFormatted(getString(r, "13", true));
                o = r.get("14");
                if (o instanceof Long) {
                    standing.setBestTime((Long) o);
                } else { // drivers setting no time will have an empty string ("14":"")
                    standing.setBestTime(-1L);
                }
                standing.setClubId(getInt(r, "15"));
                standing.setPosition(getLong(r, "18"));
                standings.add(standing);
            }
            output.setStandings(standings);
        }
    } catch (ParseException ex) {
        Logger.getLogger(TimeTrialResultStandingsParser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return output;
}

From source file:com.mycompany.test.Jaroop.java

/**
 * @param response response string which is in JSON format.
 * This method parses the JSON formatted data and prints the output.
 *//*  ww w . j a v a2  s.c  om*/
private static void parseJSON(String response) {
    try {
        JSONParser jsonParser = new JSONParser();
        JSONObject jsonObject = (JSONObject) jsonParser.parse(response);
        String output = jsonObject.get("extract").toString();
        System.out.print(output);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}