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

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

Introduction

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

Prototype

public Object parse(Reader in) throws IOException, ParseException 

Source Link

Usage

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);/*from  w ww. j a  v  a2  s  .  c om*/
    }

    return wayPointList;
}

From source file:com.mycompany.test.Jaroop.java

/**
 * @param response response string which is in JSON format.
 * This method parses the JSON formatted data and prints the output.
 *///from  w ww.  j a v  a 2s.c o  m
private static void parseJSON(String response) {
    try {
        JSONParser jsonParser = new JSONParser();
        JSONObject jsonObject = (JSONObject) jsonParser.parse(response);
        String output = jsonObject.get("extract").toString();
        System.out.print(output);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:iracing.webapi.LicenseLevelParser.java

static List<LicenseLevel> parse(String json) {
    //var licenseLevels = extractJSON('{"22":{"groupId":6,"name":"Pro+%282.0%29","id":22,"colorIndex":240},"23":{"groupId":6,"name":"Pro+%283.0%29","id":23,"colorIndex":240},"24":{"groupId":6,"name":"Pro+%284.0%29","id":24,"colorIndex":240},"25":{"groupId":7,"name":"Pro%2FWC+%281.0%29","id":25,"colorIndex":240},"26":{"groupId":7,"name":"Pro%2FWC+%282.0%29","id":26,"colorIndex":240},"27":{"groupId":7,"name":"Pro%2FWC+%283.0%29","id":27,"colorIndex":240},"28":{"groupId":7,"name":"Pro%2FWC+%284.0%29","id":28,"colorIndex":240},"10":{"groupId":3,"name":"Class+C+%282.0%29","id":10,"colorIndex":116},"11":{"groupId":3,"name":"Class+C+%283.0%29","id":11,"colorIndex":116},"12":{"groupId":3,"name":"Class+C+%284.0%29","id":12,"colorIndex":116},"13":{"groupId":4,"name":"Class+B+%281.0%29","id":13,"colorIndex":86},"14":{"groupId":4,"name":"Class+B+%282.0%29","id":14,"colorIndex":86},"15":{"groupId":4,"name":"Class+B+%283.0%29","id":15,"colorIndex":86},"16":{"groupId":4,"name":"Class+B+%284.0%29","id":16,"colorIndex":86},"17":{"groupId":5,"name":"Class+A+%281.0%29","id":17,"colorIndex":107},"18":{"groupId":5,"name":"Class+A+%282.0%29","id":18,"colorIndex":107},"19":{"groupId":5,"name":"Class+A+%283.0%29","id":19,"colorIndex":107},"1":{"groupId":1,"name":"Rookie+%281.0%29","id":1,"colorIndex":112},"2":{"groupId":1,"name":"Rookie+%282.0%29","id":2,"colorIndex":112},"3":{"groupId":1,"name":"Rookie+%283.0%29","id":3,"colorIndex":112},"4":{"groupId":1,"name":"Rookie+%284.0%29","id":4,"colorIndex":112},"5":{"groupId":2,"name":"Class+D+%281.0%29","id":5,"colorIndex":130},"6":{"groupId":2,"name":"Class+D+%282.0%29","id":6,"colorIndex":130},"7":{"groupId":2,"name":"Class+D+%283.0%29","id":7,"colorIndex":130},"8":{"groupId":2,"name":"Class+D+%284.0%29","id":8,"colorIndex":130},"9":{"groupId":3,"name":"Class+C+%281.0%29","id":9,"colorIndex":116},"20":{"groupId":5,"name":"Class+A+%284.0%29","id":20,"colorIndex":107},"21":{"groupId":6,"name":"Pro+%281.0%29","id":21,"colorIndex":240}}');
    JSONParser parser = new JSONParser();
    List<LicenseLevel> output = null;
    try {/*from ww  w. ja  v a  2 s  . c o  m*/
        JSONObject root = (JSONObject) parser.parse(json);
        output = new ArrayList<LicenseLevel>();
        for (Object key : root.keySet()) {
            LicenseLevel ll = new LicenseLevel();
            JSONObject o = (JSONObject) root.get(key);
            ll.setLicenseGroupId(getInt(o, "groupId"));
            ll.setName(getString(o, "name", true));
            ll.setId(getInt(o, "id"));
            output.add(ll);
        }
    } catch (ParseException ex) {
        Logger.getLogger(LicenseLevelParser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return output;
}

From source file:autoancillarieslimited.action.item.DeleteFile.java

public static Item parserItem(String dataJson) {
    try {//from w w w .  j  a  v a  2  s.  c  om
        Item i = new Item();
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(dataJson);
        JSONObject jsonObject = (JSONObject) obj;
        int id = Integer.parseInt((String) jsonObject.get("P0"));
        System.out.println(id);
        String file_delete = (String) jsonObject.get("P1");
        i.setId(id);
        i.setImages(file_delete);
        return i;
    } catch (Exception ex) {
        return null;
    }
}

From source file:au.edu.unsw.cse.soc.federatedcloud.community.driven.cloudbase.util.LinkedObjectModelFactory.java

public static JSONObject generateObjectFromFile(File file) throws IOException, ParseException {
    JSONParser parser = new JSONParser();

    JSONObject jsonObject = null;/*w ww .  java  2 s  .  co m*/
    jsonObject = (JSONObject) parser.parse(new FileReader(file));
    return jsonObject;
}

From source file:iracing.webapi.TimeTrialResultStandingsParser.java

public static TimeTrialResultStandings parse(String json) {
    TimeTrialResultStandings output = null;
    JSONParser parser = new JSONParser();
    try {//from   w w w  .  j av a2  s .  c  o m
        JSONObject root = (JSONObject) parser.parse(json);
        Object o = root.get("d");
        if (o instanceof JSONObject) {
            JSONObject d = (JSONObject) o;
            output = new TimeTrialResultStandings();
            String s = (String) d.get("3");
            output.setApiUserRow(Integer.parseInt(s));
            output.setTotalRecords(getInt(d, "17"));
            JSONArray arrayRoot = (JSONArray) d.get("r");
            List<TimeTrialResultStanding> standings = new ArrayList<TimeTrialResultStanding>();
            for (int i = 0; i < arrayRoot.size(); i++) {
                JSONObject r = (JSONObject) arrayRoot.get(i);
                TimeTrialResultStanding standing = new TimeTrialResultStanding();
                o = r.get("1");
                if (o instanceof Double) {
                    standing.setPoints((Double) o);
                } else if (o instanceof Long) {
                    standing.setPoints(Double.parseDouble(String.valueOf(o)));
                }
                standing.setLicenseSubLevel(getString(r, "2"));
                standing.setMaxLicenseLevel(getInt(r, "4"));
                standing.setRank(getInt(r, "5"));
                standing.setDivision(getInt(r, "7"));
                standing.setDriverName(getString(r, "8", true));
                standing.setDriverCustomerId(getLong(r, "10"));
                standing.setTotalStarts(getInt(r, "12"));
                standing.setBestTimeFormatted(getString(r, "13", true));
                o = r.get("14");
                if (o instanceof Long) {
                    standing.setBestTime((Long) o);
                } else { // drivers setting no time will have an empty string ("14":"")
                    standing.setBestTime(-1L);
                }
                standing.setClubId(getInt(r, "15"));
                standing.setPosition(getLong(r, "18"));
                standings.add(standing);
            }
            output.setStandings(standings);
        }
    } catch (ParseException ex) {
        Logger.getLogger(TimeTrialResultStandingsParser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return output;
}

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//from   w ww .  jav a2 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.dubture.symfony.core.preferences.ProjectOptions.java

/**
 * //from w w  w  .  ja  va 2 s.c o  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:currencyexchange.JSONCurrency.java

public static ArrayList<CurrencyUnit> getCurrencyUnitsJSON() {
    try {/*from  ww  w.  j a  v  a  2 s  . c om*/
        FileReader reader = new FileReader(filePath);

        JSONParser jsonParser = new JSONParser();
        JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);

        JSONArray currencyUnits = (JSONArray) jsonObject.get("units");

        ArrayList<CurrencyUnit> currencies = new ArrayList<CurrencyUnit>();

        Iterator i = currencyUnits.iterator();
        while (i.hasNext()) {
            JSONObject e = (JSONObject) i.next();
            CurrencyUnit currency = new CurrencyUnit((String) e.get("CountryCurrency"),
                    (String) e.get("Units"));

            currencies.add(currency);
        }
        return currencies;

    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (ParseException | NullPointerException ex) {
        ex.printStackTrace();
    }

    return null;
}

From source file:com.serena.rlc.provider.jira.domain.Project.java

public static Project parseSingle(String options) {
    JSONParser parser = new JSONParser();
    try {/*from  www.j a  v a 2 s  .c o  m*/
        Object parsedObject = parser.parse(options);
        JSONObject jsonObject = (JSONObject) parsedObject;
        Project project = parseSingle(jsonObject);
        return project;
    } catch (ParseException e) {
        logger.error("Error while parsing input JSON - " + options, e);
    }
    return null;
}