List of usage examples for org.json.simple JSONValue parse
public static Object parse(String s)
From source file:com.hortonworks.amstore.view.TaskManagerService.java
/** * Handles: POST /taskmanager/postinstalltasks Add a task to the list of * tasks This is done because of BUG: a call to viewContext.putInstanceData * inside the servlet returns ERROR 500 after a while. * //from w w w. ja va2 s. c o m * @param headers * http headers * @param ui * uri info * * @return the response */ @POST @Path("/postinstalltasks") @Produces({ "text/html" }) public Response addPostInstallTasks(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws IOException { String current = viewContext.getInstanceData("post-install-tasks"); if (current == null) current = "[]"; JSONArray array = (JSONArray) JSONValue.parse(current); array.add(body); viewContext.putInstanceData("post-install-tasks", array.toString()); String output = "Added task:" + body; return Response.ok(output).type("text/html").build(); }
From source file:main.java.gov.wa.wsdot.candidate.evaluation.App.java
/** * Using methods from org.json.simple to create a JSONArray object from a * JSON string.//from w w w .ja v a 2s . c o m * * @param jsonString a string representation of a JSON object * @return JSONArray object with camera data */ private JSONArray generateJSON(String jsonString) { return (JSONArray) JSONValue.parse(jsonString); }
From source file:compare.handler.get.CompareGetHandler.java
/** * Fetch and load an MVD// www .j av a2 s .c om * @param db the database * @param docID the document identifier to fetch * @return the loaded MVD * @throws CompareException if not found */ protected EcdosisMVD loadMVD(String db, String docID) throws CompareException { try { String data = Connector.getConnection().getFromDb(db, docID); if (data != null && data.length() > 0) { JSONObject doc = (JSONObject) JSONValue.parse(data); if (doc != null) return new EcdosisMVD(doc); } throw new CompareException("MVD not found " + docID); } catch (Exception e) { throw new CompareException(e); } }
From source file:com.wasteofplastic.acidisland.Update.java
/** * Query the API to find the latest approved file's details. * //from w w w . java2s . c o m * @return true if successful */ public boolean query() { URL url = null; try { // Create the URL to query using the project's ID url = new URL(API_HOST + API_QUERY + projectID); } catch (MalformedURLException e) { // There was an error creating the URL e.printStackTrace(); return false; } try { // Open a connection and query the project URLConnection conn = url.openConnection(); if (apiKey != null) { // Add the API key to the request if present conn.addRequestProperty("X-API-Key", apiKey); } // Add the user-agent to identify the program conn.addRequestProperty("User-Agent", "ASkyBlockAcidIsland Update Checker"); // Read the response of the query // The response will be in a JSON format, so only reading one line // is necessary. final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String response = reader.readLine(); // Parse the array of files from the query's response JSONArray array = (JSONArray) JSONValue.parse(response); if (array.size() > 0) { // Get the newest file's details JSONObject latest = (JSONObject) array.get(array.size() - 1); // Get the version's title versionName = (String) latest.get(API_NAME_VALUE); // Get the version's link versionLink = (String) latest.get(API_LINK_VALUE); // Get the version's release type versionType = (String) latest.get(API_RELEASE_TYPE_VALUE); // Get the version's file name versionFileName = (String) latest.get(API_FILE_NAME_VALUE); // Get the version's game version versionGameVersion = (String) latest.get(API_GAME_VERSION_VALUE); return true; } else { System.out.println("There are no files for this project"); return false; } } catch (IOException e) { // There was an error reading the query e.printStackTrace(); return false; } }
From source file:name.martingeisse.wicket.component.tree.TreeAjaxBehavior.java
/** * /*from w w w. ja va2 s.c o m*/ */ private static Object getJsonParameter(final IRequestParameters parameters, final String name, final String encodedDefaultValue) { String encodedValue = parameters.getParameterValue(name).toString(); if (encodedValue == null) { encodedValue = encodedDefaultValue; } return JSONValue.parse(encodedValue); }
From source file:com.orthancserver.OrthancConnection.java
public Object ReadJson(String uri) throws IOException { String content = ReadString(uri); Object json = JSONValue.parse(content); if (json == null) { throw new IOException(); } else {/*from w w w. j a v a2 s.c o m*/ return json; } }
From source file:formatter.handler.get.FormatterGetHandler.java
/** * Fetch and load an MVD//from ww w . j a v a 2 s . c o m * @param db the database * @param docID * @return the loaded MVD * @throws an FormatterException if not found */ protected EcdosisMVD loadMVD(String db, String docID) throws FormatterException { try { String data = Connector.getConnection().getFromDb(db, docID); if (data.length() > 0) { JSONObject doc = (JSONObject) JSONValue.parse(data); if (doc != null) return new EcdosisMVD(doc); } throw new FormatterException("MVD not found " + docID); } catch (Exception e) { throw new FormatterException(e); } }
From source file:models.Document.java
/** * @param format The RDF serialization format to represent this document as * @return This documents, in the given RDF format *///from w w w .j a v a 2s. c o m public String as(final Format format) { // NOPMD final JsonLdConverter converter = new JsonLdConverter(format); final String json = JSONValue.toJSONString(JSONValue.parse(source)); String result = ""; try { result = converter.toRdf(json); } catch (BadURIException x) { Logger.error(x.getMessage(), x); } return result; }
From source file:fr.free.movierenamer.utils.URIRequest.java
private static JSONObject getJsonDocument(Reader reader) { return (JSONObject) JSONValue.parse(reader); }
From source file:com.p000ison.dev.simpleclans2.util.JSONUtil.java
public static <T> List<T> JSONToList(String json, List<T> list) { if (json == null || json.isEmpty()) { return null; }// ww w. j a va 2 s. c om JSONArray parser = (JSONArray) JSONValue.parse(json); if (parser == null) { return null; } for (Object obj : parser) { list.add((T) obj); } return list; }