Example usage for org.json.simple JSONValue parse

List of usage examples for org.json.simple JSONValue parse

Introduction

In this page you can find the example usage for org.json.simple JSONValue parse.

Prototype

public static Object parse(String s) 

Source Link

Usage

From source file:br.ufrgs.ufrgsmapas.network.ExtraInfoParser.java

/**
 * Get the information for a buildingVo/*from w w  w  .  j a  va2s . c  o m*/
 * @param buildingVo The incomplete BuildingVo object. The extra information will be added to
 *                 this object.
 * @return The same BuildingVo object.
 */
private static BuildingVo fillBuildingInformation(BuildingVo buildingVo) {

    int buildingId = buildingVo.id;
    String URL = BASE_URL + buildingId;

    // Read JSON File
    Connection con = HttpConnection.connect(URL);
    con.method(Connection.Method.POST).ignoreContentType(true);
    Connection.Response resp;
    try {
        resp = con.execute();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    String jsonDoc = resp.body();

    JSONObject jsonStartObject = (JSONObject) JSONValue.parse(jsonDoc);

    // Create a BuildingVo object
    buildingVo.name = (String) jsonStartObject.get("NomePredio");
    buildingVo.ufrgsBuildingCode = (String) jsonStartObject.get("CodPredioUFRGS");
    buildingVo.buildingAddress = (String) jsonStartObject.get("Logradouro");
    buildingVo.buildingAddressNumber = (String) jsonStartObject.get("NrLogradouro");
    buildingVo.zipCode = (String) jsonStartObject.get("CEP");
    buildingVo.neighborhood = (String) jsonStartObject.get("Bairro");
    buildingVo.city = (String) jsonStartObject.get("Cidade");
    buildingVo.state = (String) jsonStartObject.get("UF");
    buildingVo.campusCode = Integer.valueOf((String) jsonStartObject.get("Campus"));
    buildingVo.isExternalBuilding = (String) jsonStartObject.get("IndicadorPredioExterno");
    buildingVo.description = (String) jsonStartObject.get("Descricao");
    buildingVo.phone = (String) jsonStartObject.get("TelefonePortaria");
    buildingVo.isHistorical = (String) jsonStartObject.get("IndicadorPredioHistorico");
    buildingVo.locationUrl = (String) jsonStartObject.get("URLLocalizacao");

    return buildingVo;

}

From source file:at.rocworks.oa4j.logger.logger.DataSink.java

private void createGroups() {
    // Logging Groups
    JDebug.out.info("logging groups...");
    int gcount;//from   w w w .jav a  2  s .co  m
    String gprimary = settings.getStringProperty("logger", "primary", "");
    String sgroups = settings.getStringProperty("logger", "groups", "");
    try {
        JSONArray jgroups = (JSONArray) JSONValue.parse(sgroups);
        gcount = jgroups.size();
        for (int j = 0; j < gcount; j++) {
            if (createGroup(settings, jgroups.get(j).toString())) {
                if (gprimary.isEmpty()) {
                    gprimary = jgroups.get(j).toString();
                }
            }
        }
        JDebug.out.log(Level.CONFIG, "primary={0}", gprimary);
        logger.setReadGroup(gprimary);
    } catch (java.lang.ClassCastException ex) {
        JDebug.out.log(Level.SEVERE, "not a valid json group string '{0} [{1}]'!",
                new Object[] { sgroups, ex.toString() });
    }
}

From source file:com.eclipsesource.json.performancetest.jsonrunners.SimpleRunner.java

@Override
public Object readFromReader(Reader reader) {
    return JSONValue.parse(reader);
}

From source file:me.neatmonster.spacertk.PanelListener.java

/**
 * Interprets a raw command from the panel
 * @param string input from panel//w  ww . j av  a  2  s  .c o m
 * @return result of the action
 * @throws InvalidArgumentsException Thrown when the wrong arguments are used by the panel
 * @throws UnhandledActionException Thrown when there is no handler for the action
 */
@SuppressWarnings("unchecked")
private static Object interpret(final String string)
        throws InvalidArgumentsException, UnhandledActionException {
    final int indexOfMethod = string.indexOf("?method=");
    final int indexOfArguments = string.indexOf("&args=");
    final int indexOfKey = string.indexOf("&key=");
    final String method = string.substring(indexOfMethod + 8, indexOfArguments);
    final String argumentsString = string.substring(indexOfArguments + 6, indexOfKey);
    final List<Object> arguments = (List<Object>) JSONValue.parse(argumentsString);
    try {
        if (SpaceRTK.getInstance().actionsManager.contains(method))
            return SpaceRTK.getInstance().actionsManager.execute(method, arguments.toArray());
    } catch (final InvalidArgumentsException e) {
        e.printStackTrace();
    } catch (final UnhandledActionException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:logic.ZybezQuery.java

public ArrayList<String> getItemIDList() {

    ArrayList<String> itemIDs = new ArrayList();

    try {//  www . j  a v a  2s.co  m
        String s = getJsonString();
        JSONArray array = (JSONArray) JSONValue.parse(s);
        int numItems = array.size();

        for (int i = 0; i < numItems; i++) {
            JSONObject o = ((JSONObject) array.get(i));
            itemIDs.add(o.get("id").toString());

        }

    } catch (IOException ex) {
        Logger.getLogger(ZybezQuery.class.getName()).log(Level.SEVERE, null, ex);
    }
    return itemIDs;
}

From source file:com.p000ison.dev.simpleclans2.util.JSONUtil.java

public static Map<Integer, Boolean> JSONToPermissionMap(String json, Map<Integer, Boolean> output) {
    if (json == null || json.isEmpty()) {
        return null;
    }/*from   w ww . j  a va 2  s .  c  o  m*/

    JSONObject parser = (JSONObject) JSONValue.parse(json);

    if (parser == null) {
        return null;
    }

    for (Object obj : parser.entrySet()) {
        Map.Entry entry = (Map.Entry) obj;
        Integer integer;
        //
        //Keys in json maps are always strings!
        //
        if (entry.getKey() instanceof String) {
            integer = Integer.parseInt((String) entry.getKey());
        } else {
            integer = (Integer) entry.getKey();
        }
        output.put(integer, (Boolean) entry.getValue());
    }

    return output;
}

From source file:com.opensoc.parsing.parsers.BasicLancopeParser.java

@SuppressWarnings("unchecked")
@Override//from   w w w  . j av a 2  s  .c o  m
public JSONObject parse(byte[] msg) {

    JSONObject payload = null;

    try {

        String raw_message = new String(msg, "UTF-8");

        payload = (JSONObject) JSONValue.parse(raw_message);

        String message = payload.get("message").toString();
        String[] parts = message.split(" ");
        payload.put("ip_src_addr", parts[6]);
        payload.put("ip_dst_addr", parts[7]);

        String fixed_date = parts[5].replace('T', ' ');
        fixed_date = fixed_date.replace('Z', ' ').trim();

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date date;

        date = formatter.parse(fixed_date);
        payload.put("timestamp", date.getTime());

        payload.remove("@timestamp");
        payload.remove("message");
        payload.put("original_string", message);

        return payload;
    } catch (Exception e) {

        _LOG.error("Unable to parse message: " + payload.toJSONString());
        return null;
    }
}

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

public static List<GraphOperation> loadList(File f)
        throws FileNotFoundException, GraphOperationSerializationException {

    FileReader rd = new FileReader(f);
    BufferedReader br = new BufferedReader(rd);
    JSONArray arr = (JSONArray) JSONValue.parse(br);
    return loadList(arr);
}

From source file:montocalculatorcli.MontoManager.java

public String receiveProduct() {
    if (isConnected) {
        String rawMessage = new String(fromMonto.recv());
        JSONObject message = (JSONObject) JSONValue.parse(rawMessage);
        return (String) message.get("contents");
    } else {/* w w  w. j ava2 s  .c om*/
        return "Error: Connection to Monto was closed";
    }
}

From source file:formatter.handler.get.MetadataHandler.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response, String urn)
        throws FormatterException {
    // we need the docid only
    // return the metadata for the document
    try {/*  w  w  w  .  j  a  v a2s  .c o m*/
        this.docid = request.getParameter(Params.DOCID);
        Connection conn = Connector.getConnection();
        String bson = conn.getFromDb(Database.METADATA, docid);
        if (bson != null) {
            JSONObject jObj = (JSONObject) JSONValue.parse(bson);
            JSONArray sources;
            if (jObj.containsKey(JSONKeys.SOURCES)) {
                sources = (JSONArray) jObj.get(JSONKeys.SOURCES);
            } else
                sources = new JSONArray();
            response.setContentType("application/json");
            response.getWriter().write(sources.toJSONString());
        }
    } catch (Exception e) {
        throw new FormatterException(e);
    }
}