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:it.polimi.logging.LogMessageUtils.java

public static String getEventType(String message) {
    JSONParser parser = new JSONParser();
    JSONObject jsonMsg;
    String type = "";
    try {/*  w w  w.j a  va2 s. com*/
        jsonMsg = (JSONObject) parser.parse(message);
        type = (String) jsonMsg.get(JsonStrings.EVENT_TYPE);
        return type;
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:it.polimi.logging.LogMessageUtils.java

public static long getTimestamp(String message) {
    JSONParser parser = new JSONParser();
    JSONObject jsonMsg;
    long timestamp;
    try {/*from   w ww .j a v a 2  s .co  m*/
        jsonMsg = (JSONObject) parser.parse(message);
        timestamp = (long) jsonMsg.get(JsonStrings.TIMESTAMP);
        return timestamp;
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return -1;
}

From source file:it.polimi.logging.LogMessageUtils.java

public static String getLogId(String message) {
    JSONParser parser = new JSONParser();
    JSONObject jsonMsg;
    String logId = "";
    try {/*from  w w  w.ja v  a  2s .c  om*/
        jsonMsg = (JSONObject) parser.parse(message);
        logId = (String) jsonMsg.get(JsonStrings.LOG_ID);
        return logId;
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:it.polimi.logging.LogMessageUtils.java

public static String getTopicReply(String message) {
    JSONParser parser = new JSONParser();
    JSONObject jsonMsg;
    String topic = "";
    try {//ww  w  .  j a  v  a  2  s  .  c om
        jsonMsg = (JSONObject) parser.parse(message);
        topic = (String) jsonMsg.get(JsonStrings.TOPIC_REPLY);
        return topic;
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:com.blogspot.ryanfx.auth.GoogleUtil.java

/**
 * Returns an email address associated with an auth token, if it exists.
 * @param token auth token//from  w w w  .j  a  v  a 2 s . c  o  m
 * @return
 * @throws LoginException
 * @throws IOException
 * @throws ParseException
 */
public static String submitUserToken(String token) throws LoginException, IOException, ParseException {
    JSONObject jsonObject = null;
    String email = null;
    JSONParser parser = new JSONParser();
    String jsonResult = null;
    jsonResult = issueTokenGetRequest(token);
    if (jsonResult != null) {
        jsonObject = (JSONObject) parser.parse(jsonResult);
        //Gets the email value from the json result
        email = (String) jsonObject.get("email");
        //Logs the request for our knowledge
        Logger.getLogger(GoogleUtil.class.getName()).severe("Garage request from user: " + email);
    }
    return email;
}

From source file:it.polimi.geinterface.filter.PropertiesFilter.java

protected static Filter buildJSONPathFilter(JSONObject json) {

    if (json == null)
        return null;
    if (json.size() != 3) {
        System.err.println("No 3 keys for object " + json);
        return null;
    }/* w w  w. j  av a2 s  . c  o  m*/

    String operand = (String) json.get(ReservedKeys.$op.name());
    FilterType op_type = FilterType.valueOf(operand);

    if (op_type.ordinal() <= FilterType.OR.ordinal()) {
        if (op_type.equals(FilterType.AND))
            return buildJSONPathFilter((JSONObject) json.get(ReservedKeys.$filter_1.name()))
                    .and(buildJSONPathFilter((JSONObject) json.get(ReservedKeys.$filter_2.name())));

        return buildJSONPathFilter((JSONObject) json.get(ReservedKeys.$filter_1.name()))
                .or(buildJSONPathFilter((JSONObject) json.get(ReservedKeys.$filter_2.name())));

    } else {
        String key = (String) json.get(ReservedKeys.$key.name());
        String val = "" + json.get(ReservedKeys.$val.name());
        if (op_type.equals(FilterType.CONTAINS))
            return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name()))
                    .contains(json.get(ReservedKeys.$val.name())));

        if (op_type.equals(FilterType.EQUALS))
            return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name()))
                    .eq(json.get(ReservedKeys.$val.name())));

        if (op_type.equals(FilterType.GT))
            return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name()))
                    .gt(json.get(ReservedKeys.$val.name())));

        if (op_type.equals(FilterType.LT))
            return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name()))
                    .lt(json.get(ReservedKeys.$val.name())));

        if (op_type.equals(FilterType.EXISTS))
            return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name()))
                    .exists((boolean) json.get(ReservedKeys.$val.name())));

        if (op_type.equals(FilterType.NOT_EXISTS))
            return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name()))
                    .exists((boolean) json.get(ReservedKeys.$val.name())));
    }

    return null;
}

From source file:it.polimi.logging.LogMessageUtils.java

public static LogType getLogType(String message) {
    JSONParser parser = new JSONParser();
    JSONObject jsonMsg;
    String logType = "";
    try {/*  w w w  . j a  v  a2 s .c om*/
        jsonMsg = (JSONObject) parser.parse(message);
        logType = (String) jsonMsg.get(JsonStrings.LOG_TYPE);
        return LogType.valueOf(logType);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:it.polimi.logging.LogMessageUtils.java

public static String getSenderID(String msgJson) {
    JSONParser parser = new JSONParser();
    JSONObject jsonMsg;
    String senderID = "";
    try {//from   w  w w. j av a2  s.  c  om
        jsonMsg = (JSONObject) parser.parse(msgJson);
        senderID = (String) jsonMsg.get(JsonStrings.SENDER);
        return senderID;
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:com.google.api.services.samples.prediction.cmdline.PredictionSample.java

private static Insert2 responseToObject(String jsonString) {

    Insert2 res = new Insert2();
    JSONParser parser = new JSONParser();
    try {//w w w. jav a  2  s  .c  o  m

        JSONObject obj = (JSONObject) parser.parse(jsonString);
        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        res.setCreated(new DateTime((Date) formatter.parse((String) obj.get("created"))));
        res.setId((String) obj.get("id"));
        res.setKind((String) obj.get("kind"));
        res.setSelfLink((String) obj.get("selfLink"));
        res.setTrainingStatus((String) obj.get("trainingStatus"));

        if (obj.get("trainingComplete") != null) {

            res.setTrainingComplete(new DateTime((Date) formatter.parse((String) obj.get("trainingComplete"))));
            JSONObject ml = (JSONObject) obj.get("modelInfo");
            Insert2.ModelInfo modelInfo = new ModelInfo();
            modelInfo.setNumberInstances(Long.parseLong((String) ml.get("numberInstances")));
            modelInfo.setModelType((String) ml.get("modelType"));
            modelInfo.setNumberLabels(Long.parseLong((String) ml.get("numberLabels")));
            modelInfo.setClassificationAccuracy((String) ml.get("classificationAccuracy"));
            res.setModelInfo(modelInfo);

        }

    } catch (ParseException e) {
        e.printStackTrace();
        res = null;
    } catch (java.text.ParseException e) {
        e.printStackTrace();
        res = null;
    }
    return res;

}

From source file:com.apigee.edge.config.utils.ConsolidatedConfigReader.java

/**
 * List of APIs under apiConfig/*  w  w w .j  a  v  a2 s.c  o m*/
 */
public static Set<String> getAPIList(File configFile) throws ParseException, IOException {

    Logger logger = LoggerFactory.getLogger(ConfigReader.class);

    JSONParser parser = new JSONParser();
    ArrayList<String> out = null;
    try {
        BufferedReader bufferedReader = new BufferedReader(new java.io.FileReader(configFile));

        JSONObject edgeConf = (JSONObject) parser.parse(bufferedReader);
        if (edgeConf == null)
            return null;

        JSONObject scopeConf = (JSONObject) edgeConf.get("apiConfig");
        if (scopeConf == null)
            return null;

        return scopeConf.keySet();

        // while( keys.hasNext() ) {
        //     out.add((String)keys.next());
        // }
    } catch (IOException ie) {
        logger.info(ie.getMessage());
        throw ie;
    } catch (ParseException pe) {
        logger.info(pe.getMessage());
        throw pe;
    }
}