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:logic.ZybezItemListing.java

private void setItemData() {

    try {/*from ww  w .ja v  a  2s.co  m*/
        listingJsonString = getJsonString();
        JSONObject o = (JSONObject) JSONValue.parse(listingJsonString);

        itemName = o.get("name").toString();
        imageURL = o.get("image").toString();
        averagePrice = o.get("average").toString();

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

}

From source file:net.bitnine.agensgraph.graph.property.Jsonb.java

@Override
public void setValue(String value) throws SQLException {
    Object o = JSONValue.parse(value);
    if (o instanceof JSONObject) {
        jsonValue = new JsonObject((JSONObject) o);
    } else if (o instanceof JSONArray) {
        jsonValue = new JsonArray((JSONArray) o);
    } else {//from   w w w.j  a  va  2s .c om
        jsonValue = o;
    }
    setJsonType(jsonValue);
}

From source file:de.cgarbs.lib.json.type.JSONTypeFactoryTest.java

@Test
public void checkUnwrapJSONObject() throws JSONException {
    assertThat(/* w w  w  .ja  va 2  s  . com*/
            JSONTypeFactory.unwrapJSONObject(
                    JSONValue.parse("{\"class\":\"JSONColor\",\"version\":\"1\",\"attributes\":{}}")),
            is(instanceOf(JSONColor.class)));
}

From source file:com.jgoetsch.eventtrader.source.parser.ApePayloadParser.java

public boolean parseContent(InputStream input, long length, String contentType, MsgHandler handler)
        throws IOException, MsgParseException {
    JSONArray json = (JSONArray) JSONValue.parse(new BufferedReader(new InputStreamReader(input)));
    for (Object rawObj : json) {
        log.info("Received raw message " + rawObj.toString());
        JSONObject raw = (JSONObject) rawObj;
        String rawType = (String) raw.get("raw");
        JSONObject data = (JSONObject) raw.get("data");

        if (!payload.parseData(rawType, data, handler))
            return false;
    }/*  w  ww .java2s . co  m*/
    return true;
}

From source file:formatter.handler.FormatterHandler.java

/**
* Get the document body of the given urn or null
* @param db the database where it is/*from  w  ww.jav a 2  s.  c o  m*/
* @param docID the docID of the resource
* @return the document body or null if not present
*/
private static String getDocumentBody(String db, String docID) throws FormatterException {
    try {
        String jStr = Connector.getConnection().getFromDb(db, docID);
        if (jStr != null) {
            JSONObject jDoc = (JSONObject) JSONValue.parse(jStr);
            if (jDoc != null) {
                Object body = jDoc.get(JSONKeys.BODY);
                if (body != null)
                    return body.toString();
            }
        }
        throw new Exception("document " + db + "/" + docID + " not found");
    } catch (Exception e) {
        throw new FormatterException(e);
    }
}

From source file:net.jakobnielsen.imagga.color.convert.SimilarColorsConverter.java

@Override
public List<RankSimilarity> convert(String jsonString) {
    if (jsonString == null) {
        throw new ConverterException("The given JSON string is null");
    }/*www. j av a2  s  .  c  o m*/

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

    if (!json.containsKey(RANK_SIMILARITY)) {
        throw new ConverterException(RANK_SIMILARITY + " key missing from json : " + jsonString);
    }

    JSONArray jsonArray = (JSONArray) json.get(RANK_SIMILARITY);
    List<RankSimilarity> rankResults = new ArrayList<RankSimilarity>();

    for (Object co : jsonArray) {
        JSONObject o = (JSONObject) co;
        rankResults.add(new RankSimilarity(getLong("id", o), getDouble("dist", o)));
    }

    return rankResults;
}

From source file:com.storageroomapp.client.Collections.java

/**
 * Parses a String of json text and returns a Collections object.
 * It will correctly parse the Collections object if it is toplevel,
 * or also if nested in an 'array' key-value pair.
 * /*from w w  w .  j  av a  2 s.c o m*/
 * @param parent the Application object associated with the json
 * @param json the String with the json text
 * @return an Collections object, or null if the parsing failed
 */
static public Collections parseJson(Application parent, String json) {
    JSONObject root = (JSONObject) JSONValue.parse(json);
    if (root == null) {
        return null;
    }

    // unwrap the collections object if it is a value on key 'array'
    JSONObject rootArray = (JSONObject) root.get("array");
    if (rootArray != null) {
        root = rootArray;
    }
    return parseJsonObject(parent, root);
}

From source file:eu.hansolo.fx.weatherfx.GeoCode.java

/**
 * Returns name of City for given latitude and longitude
 * @param LATITUDE//from www  .j a  v a2 s  .  c o m
 * @param LONGITUDE
 * @return name of City for given latitude and longitude
 */
public static String inverseGeoCode(final double LATITUDE, final double LONGITUDE) {
    String URL_STRING = new StringBuilder(INVERSE_GEO_CODE_URL).append(LATITUDE).append(",").append(LONGITUDE)
            .append("&outFormat=json&thumbMaps=false").toString();

    StringBuilder response = new StringBuilder();
    try {
        final HttpsURLConnection CONNECTION = (HttpsURLConnection) new URL(URL_STRING).openConnection();
        final BufferedReader IN = new BufferedReader(new InputStreamReader(CONNECTION.getInputStream()));
        String inputLine;
        while ((inputLine = IN.readLine()) != null) {
            response.append(inputLine).append("\n");
        }
        IN.close();

        Object obj = JSONValue.parse(response.toString());
        JSONObject jsonObj = (JSONObject) obj;

        JSONArray results = (JSONArray) jsonObj.get("results");
        JSONObject firstResult = (JSONObject) results.get(0);
        JSONArray locations = (JSONArray) firstResult.get("locations");
        JSONObject firstLocation = (JSONObject) locations.get(0);
        return firstLocation.get("adminArea5").toString();
    } catch (IOException ex) {
        System.out.println(ex);
        return "";
    }
}

From source file:at.ac.tuwien.dsg.smartcom.integration.JSONConverter.java

public static PeerInfo getPeerInfo(Identifier peerId, String content) throws NoSuchPeerException {
    JSONObject jsonOutput = (JSONObject) JSONValue.parse(content);

    String[][] strings = parsePeerInfoResults(jsonOutput);

    if (strings == null) {
        throw new NoSuchPeerException(peerId);
    }/*from  w  ww .  j  a v  a  2s . c o m*/

    PeerInfo info = new PeerInfo();
    info.setId(peerId);
    info.setPrivacyPolicies(null);

    Map<String, PeerChannelAddress> map = new HashMap<>();

    for (String[] string : strings) {
        info.setDeliveryPolicy(DeliveryPolicy.Peer.values()[(int) Integer.valueOf(string[3])]);

        String id = string[2];

        PeerChannelAddress address = map.get(id);
        if (address == null) {
            address = new PeerChannelAddress();
            address.setPeerId(peerId);
            address.setContactParameters(new ArrayList<String>());
            address.setChannelType(Identifier.channelType(string[4]));
            map.put(id, address);
        }

        if (address.getContactParameters() == null) {
            address.setContactParameters(new ArrayList<String>());
        }

        ArrayList<String> list = (ArrayList<String>) address.getContactParameters();
        list.add(string[5]);
    }

    List<PeerChannelAddress> addresses = new ArrayList<>(map.values());
    info.setAddresses(addresses);

    return info;
}

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

@Override
public Object readFromString(String json) {
    return JSONValue.parse(json);
}