Example usage for org.json.simple.parser JSONParser JSONParser

List of usage examples for org.json.simple.parser JSONParser JSONParser

Introduction

In this page you can find the example usage for org.json.simple.parser JSONParser JSONParser.

Prototype

JSONParser

Source Link

Usage

From source file:com.serena.rlc.provider.artifactory.domain.Repository.java

public static List<Repository> parse(String options) {
    List<Repository> list = new ArrayList<>();
    JSONParser parser = new JSONParser();
    try {/*from   w w  w  . j av a2s .c  om*/
        Object parsedObject = parser.parse(options);
        JSONArray jsonArray = (JSONArray) parsedObject;
        for (Object object : jsonArray) {
            Repository rObj = parseSingle((JSONObject) object);
            list.add(rObj);
        }
    } catch (ParseException e) {
        logger.error("Error while parsing input JSON - " + options, e);
    }

    return list;
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.course.WayPointQueryService.java

public static List<IWayPoint> getWayPointList(String pilotUrl) throws IOException, ParseException {

    String jsonString = HttpQueryUtils.simpleQuery(pilotUrl + "/json/waypoints");
    if (jsonString == null || jsonString.isEmpty())
        return null;

    JSONParser parser = new JSONParser();
    JSONArray array = (JSONArray) parser.parse(jsonString);
    List<IWayPoint> wayPointList = new ArrayList<IWayPoint>();

    for (Object entry : array) {
        WayPoint wayPoint = new WayPoint((JSONObject) entry);
        wayPointList.add(wayPoint);// w w w .j  av  a 2  s  .co  m
    }

    return wayPointList;
}

From source file:com.dubture.symfony.core.preferences.ProjectOptions.java

/**
 * //from   w w w  .ja v  a2 s .co m
 * Retrieve the synthetic services of a project.
 * 
 * 
 * @param project
 * @return
 */
public static final JSONArray getSyntheticServices(IProject project) {

    JSONArray defaultSynthetics = null;

    try {

        CorePreferencesSupport prefs = CorePreferencesSupport.getInstance();

        String synths = prefs.getPreferencesValue(Keys.SYNTHETIC_SERVICES, null, project);

        Logger.debugMSG("LOADED DEFAULTS: " + synths);

        JSONParser parser = new JSONParser();
        defaultSynthetics = (JSONArray) parser.parse(synths);

    } catch (Exception e) {
        Logger.logException(e);
    }

    return defaultSynthetics;
}

From source file:at.ac.tuwien.infosys.jcloudscale.datastore.driver.couchdb.CouchDBUtil.java

/**
 * Add id and revision to the content of a given request
 *
 * @param request the given request/*  w w  w .  j  ava  2 s  . c o m*/
 * @param id the id to add
 * @param revision the revision to add
 * @return the modified request
 */
public static Request addIdAndRevisionToContent(Request request, String id, String revision) {
    JSONParser parser = new JSONParser();
    try {
        JSONObject jsonObject = (JSONObject) parser.parse((String) request.getContent());
        jsonObject.put("_id", id);
        jsonObject.put("_rev", revision);
        String jsonString = jsonObject.toJSONString();
        log.info("Updated Request content with id and rev: " + jsonString);
        return new Request.Builder(request.getProtocolType(), request.getRequestType(), request.getUrl(),
                request.getHost(), request.getPort()).contentType(request.getContentType()).content(jsonString)
                        .build();
    } catch (ParseException e) {
        throw new DatastoreException("Error parsing JSON to add revision: " + e.getMessage());
    }
}

From source file:com.polopoly.tools.minifier.FileMapConstructor.java

public Map<String, List<String>> decodeFiles(String json) throws BadJsonException {

    Map<String, List<String>> result = new HashMap<String, List<String>>();
    JSONParser parser = new JSONParser();
    try {/*from w ww.  j a v  a  2 s. co  m*/
        Object parsed = parser.parse(json);
        if (parsed instanceof JSONObject) {
            JSONObject fileMap = (JSONObject) parsed;
            for (Object fileObj : fileMap.keySet()) {
                String filename = fileObj.toString();
                Object parsedArray = fileMap.get(fileObj);
                if (parsedArray instanceof JSONArray) {
                    result.put(filename, getFilesFromMap((JSONArray) parsedArray));
                }
            }
        } else {
            throw new BadJsonException("Top level object not a string");
        }
    } catch (ParseException e) {
        throw new BadJsonException(e);
    }
    return result;
}

From source file:me.ryandowling.allmightybot.utils.TwitchAPI.java

public static void checkToken() {
    System.out.println("Checking Twitch API token");

    TwitchAPIRequest request = new TwitchAPIRequest("/");

    try {//from   w  w  w  .j  a v  a 2 s  .co m
        String response = request.get();
        JSONParser parser = new JSONParser();
        JSONObject jsonObject = (JSONObject) parser.parse(response);

        JSONObject token = (JSONObject) jsonObject.get("token");
        boolean valid = (boolean) token.get("valid");
        if (!valid) {
            System.err.println("API token not valid, exiting!");
            System.exit(1);
        }
        System.out.println("Token is valid, API connection successful!");
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Error connecting to Twitch API, exiting!");
        System.exit(1);
    } catch (ParseException e) {
        e.printStackTrace();
        System.err.println("Error occured parsing JSON from Twitch API, exiting!");
        System.exit(1);
    }

    System.out.println("Finished checking Twitch API token");
}

From source file:Model.ImportJSON.java

public ImportJSON() {
    this.parser = new JSONParser();

}

From source file:Connector.AlchemyConnector.java

public void getConnection() {

    try {//w  w  w .ja  v a 2 s  .co  m
        String envServices = System.getenv("VCAP_SERVICES");

        JSONParser parser = new JSONParser();
        Object obj = parser.parse(envServices);
        JSONObject jsonObject = (JSONObject) obj;
        JSONArray vcapArray = (JSONArray) jsonObject.get("alchemy_api");
        JSONObject vcap = (JSONObject) vcapArray.get(0);
        JSONObject credentials = (JSONObject) vcap.get("credentials");
        apiKey = credentials.get("apikey").toString();

    } catch (ParseException ex) {
    }
}

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:buspathcontroller.JSONFileParser.java

public void generateAllRoutes() {
    JSONParser parser = new JSONParser();
    try {//from   w  w w  .  j a v a 2s. c o m
        PrintWriter writer = new PrintWriter("/Users/Zhaowei/Desktop/BusPath/allRoutes.txt");
        Object obj = parser.parse(new FileReader("/Users/Zhaowei/Desktop/BusPath/RawJSON/RouteList.json"));
        JSONObject jsonObject = (JSONObject) obj;
        JSONArray routes = (JSONArray) jsonObject.get("routes");
        Iterator iterator = routes.iterator();
        while (iterator.hasNext()) {
            JSONObject route = (JSONObject) ((JSONObject) iterator.next()).get("route");
            writer.println(route.get("name") + ";" + route.get("tag") + ";" + route.get("agency"));
        }
        writer.close();
    } catch (Exception e) {
        System.out.println(e);
    }
}