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:autoancillarieslimited.parser.ParserUtil.java

public static Item parserItem(String dataJson) {
    try {//from   w w  w.  ja  v  a 2s. c  o m
        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"));
        String name = (String) jsonObject.get("P1");
        String description = (String) jsonObject.get("P3");
        int category = Integer.parseInt((String) jsonObject.get("P2"));
        double price = Double.parseDouble((String) jsonObject.get("P4"));
        String images = (String) jsonObject.get("P6");
        //     String imagesData
        i.setId(id);
        i.setName(name);
        i.setDescription(description);
        i.setPrice(price);
        i.setDate_Created(new Date());
        TypeItem typeItemByID = ProductDAO.getInstance().getTypeItemByID(category);
        i.setTypeItem(typeItemByID);
        i.setType_ID(category);
        i.setImages(images);
        return i;
    } catch (Exception ex) {
        return null;
    }
}

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  ww w .  ja  v a2  s . c  o  m
        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:iracing.webapi.LicenseGroupParser.java

public static List<LicenseGroup> parse(String json) {
    JSONParser parser = new JSONParser();
    List<LicenseGroup> output = null;
    try {/*from   w w  w. j  a  v  a2s  .  co  m*/
        JSONArray rootArray = (JSONArray) parser.parse(json);
        output = new ArrayList<LicenseGroup>();
        for (int i = 0; i < rootArray.size(); i++) {
            JSONObject r = (JSONObject) rootArray.get(i);
            LicenseGroup lg = new LicenseGroup();
            lg.setId(getInt(r, "group"));
            lg.setName(getString(r, "name", true));
            // NOTE: the following aren't specified if not applicable
            Object o = r.get("minNumTT");
            if (o != null)
                lg.setMinimumNumberOfTimeTrials(((Long) o).intValue());
            o = r.get("minNumRaces");
            if (o != null)
                lg.setMinimumNumberOfRaces(((Long) o).intValue());
            output.add(lg);
        }
    } catch (ParseException ex) {
        Logger.getLogger(LicenseGroupParser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return output;
}

From source file:it.polimi.proximityapi.jsonLogic.POIJsonParser.java

public static ArrayList<POI> parsePOIFile(String jsonString) {
    ArrayList<POI> poiList = new ArrayList<>();
    JSONParser parser = new JSONParser();

    JSONArray poiArray;//from  w ww  .ja v  a 2s  . c o m
    try {
        poiArray = (JSONArray) parser.parse(jsonString);
        for (int i = 0; i < poiArray.size(); i++) {
            JSONObject jsonPOI = (JSONObject) poiArray.get(i);
            POI poi = new POI();
            poi.setName((String) jsonPOI.get(JsonStrings.NAME));
            poi.setLatitude(Double.parseDouble((String) jsonPOI.get(JsonStrings.LATITUDE)));
            poi.setLongitude(Double.parseDouble((String) jsonPOI.get(JsonStrings.LONGITUDE)));
            if (!jsonPOI.get(JsonStrings.RADIUS).equals(""))
                poi.setRadius(Float.parseFloat((String) jsonPOI.get(JsonStrings.RADIUS)));
            else {
                //Default radius set when it is not set in the corresponding JSON object
                poi.setRadius(TechnologyManager.BT_START_GEOFENCE_RADIUS);
            }
            poi.setBeaconUuid((String) jsonPOI.get(JsonStrings.BEACON_UUID));
            poiList.add(poi);
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return poiList;
}

From source file:iracing.webapi.SeasonTimeTrialStandingsParser.java

public static SeasonTimeTrialStandings parse(String json) {
    JSONParser parser = new JSONParser();
    SeasonTimeTrialStandings output = null;
    try {/*from  w w  w  .  jav a 2 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 SeasonTimeTrialStandings();
            String s = getString(d, "5");
            output.setApiUserRow(Integer.parseInt(s));
            output.setTotalRecords(getLong(d, "18"));
            JSONArray arrayRoot = (JSONArray) d.get("r");
            List<SeasonTimeTrialStanding> standings = new ArrayList<SeasonTimeTrialStanding>();
            for (int i = 0; i < arrayRoot.size(); i++) {
                JSONObject r = (JSONObject) arrayRoot.get(i);
                SeasonTimeTrialStanding standing = new SeasonTimeTrialStanding();
                standing.setDroppedWeeks(getInt(r, "1"));
                standing.setClubName(getString(r, "2", true));
                o = r.get("3");
                if (o instanceof Double) {
                    standing.setTotalPoints((Double) o);
                } else if (o instanceof Long) {
                    standing.setTotalPoints(Double.parseDouble(String.valueOf(o)));
                }
                standing.setLicenseSubLevel(getString(r, "4"));
                standing.setMaxLicenseLevel(getInt(r, "6"));
                standing.setRank(getInt(r, "7"));
                standing.setDivision(getInt(r, "9"));
                standing.setDriverName(getString(r, "10", true));
                standing.setDriverCustomerId(getLong(r, "12"));
                standing.setTotalStarts(getInt(r, "14"));
                standing.setClubId(getInt(r, "15"));
                standing.setWeeksCounted(getInt(r, "17"));
                standing.setTotalWins(getInt(r, "19"));
                standing.setPosition(getInt(r, "20"));
                standings.add(standing);
            }
            output.setStandings(standings);
        }
    } catch (ParseException ex) {
        Logger.getLogger(SeasonTimeTrialStandingsParser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return output;
}

From source file:authorship.verification.ReadJSON.java

public static String readJson(String file) {
    JSONParser parser = new JSONParser();
    try {//from w  w  w .  j a v  a2 s.c  o m
        FileReader fileReader = new FileReader(file);
        JSONObject json = (JSONObject) parser.parse(fileReader);

        language = (String) json.get("language");
        //System.out.println("Language: " + language); 

        JSONArray filenames = (JSONArray) json.get("problems");
        Iterator i = filenames.iterator();
        /*System.out.println("Filenames: "); 
        while (i.hasNext()) { 
        System.out.println(" " + i.next()); 
        } */
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return language;
}

From source file:com.serena.rlc.provider.jenkins.domain.Job.java

public static Job parseSingle(String options) {
    JSONParser parser = new JSONParser();
    try {// w  w  w  .  ja  v a  2 s. c om
        Object parsedObject = parser.parse(options);
        JSONObject jsonObject = (JSONObject) parsedObject;
        Job job = parseSingle(jsonObject);
        return job;
    } catch (ParseException e) {
        logger.error("Error while parsing input JSON - " + options, e);
    }
    return null;
}

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

public static String getTopic(String username) throws IOException, ParseException {
    TwitchAPIRequest request = new TwitchAPIRequest("/channels/" + username);

    String response = request.get();
    JSONParser parser = new JSONParser();
    JSONObject jsonObject = (JSONObject) parser.parse(response);

    return (String) jsonObject.get("status");
}

From source file:net.sourceforge.fenixedu.dataTransferObject.externalServices.TeacherPublicationsInformation.java

public static Map<Teacher, List<String>> getTeacherPublicationsInformations(Set<Teacher> teachers) {
    Map<Teacher, List<String>> teacherPublicationsInformationMap = new HashMap<Teacher, List<String>>();

    Client client = ClientBuilder.newClient();
    WebTarget resource = client.target(BASE_URL);
    List<String> teacherIds = new ArrayList<String>();

    for (Teacher teacher : teachers) {
        teacherIds.add(teacher.getTeacherId());
    }/*ww  w  .  jav  a 2s. c om*/

    resource = resource.path(CURRICULUM_PATH).queryParam("istids", StringUtils.join(teacherIds, ","));
    try {
        String allPublications = resource.request().get(String.class);
        JSONParser parser = new JSONParser();
        for (Object teacherPublications : (JSONArray) parser.parse(allPublications)) {
            JSONObject teacherPublicationsInfo = (JSONObject) teacherPublications;
            final String username = (String) teacherPublicationsInfo.get("istID");
            final Teacher teacher = Teacher.readByIstId(username);
            JSONArray preferredPublications = (JSONArray) teacherPublicationsInfo.get("preferred");

            List<String> teacherPublicationsList = new ArrayList<String>();
            for (Object publication : preferredPublications) {
                teacherPublicationsList.add(publication.toString());
            }

            teacherPublicationsInformationMap.put(teacher, teacherPublicationsList);
        }
    } catch (ParseException e) {
        logger.error(e.getMessage(), e);
    } finally {
        client.close();
    }

    return teacherPublicationsInformationMap;
}

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

public static String setTopic(String username, String topic) throws IOException, ParseException {
    TwitchAPIRequest request = new TwitchAPIRequest("/channels/" + username);

    String response = request.put(new ChannelPutRequest(topic));

    JSONParser parser = new JSONParser();
    JSONObject jsonObject = (JSONObject) parser.parse(response);

    return (String) jsonObject.get("status");
}