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.servicenow.domain.ChangeTask.java

public static List<ChangeTask> parse(String options) {
    List<ChangeTask> ctList = new ArrayList<>();
    JSONParser parser = new JSONParser();
    try {//ww w  . jav a 2  s .co m
        Object parsedObject = parser.parse(options);
        JSONArray jsonArray = (JSONArray) getJSONValue((JSONObject) parsedObject, "result");
        for (Object object : jsonArray) {
            ChangeTask ctObj = parseSingle((JSONObject) object);
            ctList.add(ctObj);
        }
    } catch (ParseException e) {
        logger.error("Error while parsing input JSON - " + options, e);
    }
    return ctList;
}

From source file:autoancillarieslimited.action.employee.CheckLogin.java

public String execute() throws Exception {
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(data_request);
    JSONObject jsonObject = (JSONObject) obj;
    String user = (String) jsonObject.get("P0");
    String pass = (String) jsonObject.get("P1");
    Employee checkLogin = EmployeeDAO.getInstance().checkLogin(user, pass);
    Admin checkLoginAdmin = EmployeeDAO.getInstance().checkLoginAdmin(user, pass);
    if (checkLoginAdmin != null) {
        code = 401;/*  ww  w  . j a  va  2s .c om*/
        map.put("USER-ADMIN", checkLoginAdmin);
        return SUCCESS;
    } else if (checkLogin != null) {
        code = 400;
        map.put("USER-EMPLOYEE", checkLogin);
    } else {
        code = 405;
        data_response = "Login Faild. Check your email or password!";
    }
    return SUCCESS;
}

From source file:jenkins.plugins.testrail.util.TestRailJsonParser.java

/**
 *
 * @param json//  w w  w . j  av a 2s. com
 * @return
 */
public List<String> decodeGetPlanJSON(String json) {
    List<String> returnList = new ArrayList<String>();
    System.out.println("Parsing json");
    try {
        JSONObject rootJsonObject = (JSONObject) new JSONParser().parse(json);
        JSONArray entriesJsonArray = (JSONArray) rootJsonObject.get("entries");
        for (Object entryObject : entriesJsonArray) {
            JSONObject entryJsonObject = (JSONObject) entryObject;
            JSONArray runsJsonArray = (JSONArray) entryJsonObject.get("runs");
            for (Object runObject : runsJsonArray) {
                JSONObject runJsonObject = (JSONObject) runObject;
                returnList.add(runJsonObject.get("id").toString());
            }
        }
    } catch (ParseException pe) {
        System.out.println("Exception caught: " + pe.getPosition());
        System.out.println(pe);
    }

    return returnList;
}

From source file:com.hurence.logisland.repository.json.JsonTagsFileParser.java

/**
 * parses the file and returns a dictionnary of domain / tags
 *
 * @param filename/*from   ww  w.j av  a 2s .  com*/
 * @return
 */
public Map<String, List<String>> parse(String filename) {

    Map<String, List<String>> repository = new HashMap<>();
    JSONParser parser = new JSONParser();
    int domainCount = 0;

    try {

        logger.debug("parsing json file : " + filename);
        Object obj = parser.parse(new FileReader(filename));

        JSONArray domains = (JSONArray) obj;

        for (Object object : domains) {
            domainCount++;
            JSONObject jsonObject = (JSONObject) object;
            String domain = (String) jsonObject.get("term");

            JSONArray tags = (JSONArray) jsonObject.get("tags");

            String company = (String) jsonObject.get("company");
            if (company != null) {
                tags.add(company);
            }

            repository.put(domain, tags);
        }

        logger.debug("succesfully parsed " + domainCount + "domains");

    } catch (ParseException | IOException ex) {
        logger.error(ex.getMessage());
    }

    return repository;

}

From source file:manager.GameElement.java

public static void load() throws FileNotFoundException, IOException, ParseException, InstantiationException,
        IllegalAccessException {/* ww  w.  j  ava 2 s . co  m*/
    BufferedReader br = new BufferedReader(new FileReader("scores.json"));
    JSONParser parser = new JSONParser();
    String line = br.readLine();
    if (line != null)
        fromJSON((JSONObject) parser.parse(line));
}

From source file:com.conwet.silbops.msg.NotifyMsgTest.java

@Test
public void testJSONRoundtrip() throws ParseException {

    NotifyMsg msg = new NotifyMsg();
    msg.setNotification(/*w  w  w  . j  a va  2 s . com*/
            new Notification().attribute("attr1", Type.STRING, "val1").attribute("attr2", Type.STRING, "one"));

    String jsonStr = msg.toJSONString();
    JSONObject json = (JSONObject) new JSONParser().parse(jsonStr);
    assertThat(NotifyMsg.fromJSON(json)).isEqualTo(msg);
}

From source file:ch.newscron.newscronjsp.ReferralSignUpServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {//from w  w  w . jav  a 2 s .  c  om

        String[] urlPartsPath = request.getRequestURI().split("/");
        String encodedDataString = urlPartsPath[urlPartsPath.length - 1];

        String decodedDataString = Encryption.decode(encodedDataString);

        if (decodedDataString != null) {
            JSONParser parser = new JSONParser();
            JSONObject decodedJSON = (JSONObject) parser.parse(decodedDataString);

            String dateValidity = (String) decodedJSON.get("val");
            if (isDateValid(dateValidity)) { // Date validity not expired & not null from decoding URL
                String rewardNewUser = (String) decodedJSON.get("rew2");
                String signupPageReferral = "%s/%s";
                signupPageReferral = String.format(signupPageReferral, encodedDataString,
                        Base64.encodeBase64URLSafeString(rewardNewUser.getBytes()));
                signupPage += signupPageReferral;
            }
        }

    } catch (Exception ex) {
        Logger.getLogger(ShortUrlCreator.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        response.sendRedirect(signupPage);
    }
}

From source file:autoancillarieslimited.action.customer.ChangePasswordAction.java

public String execute() throws Exception {
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(data_request);

    JSONObject jsonObject = (JSONObject) obj;
    String currentPassword = (String) jsonObject.get("P0");
    String password1 = (String) jsonObject.get("P1");
    String password2 = (String) jsonObject.get("P2");
    Customer customer = (Customer) map.get("USER");
    if (!currentPassword.equals(customer.getPassWord())) {
        code = StringUtils.FAILD;//from w ww .  ja va2 s  .c  o  m
        data_response = "Old Password is not correct";
        return SUCCESS;
    }
    if (!password1.equals(password2)) {
        code = StringUtils.FAILD;
        data_response = "Old Password is not correct";
    }
    customer.setPassWord(password2);
    CustomerDAO.getInstance().update(customer);
    map.put("USER", customer);
    code = 400;
    data_response = "Change Password Success";
    return SUCCESS;
}

From source file:kr.co.bitnine.octopus.schema.metamodel.OctopusMetaModelDataSource.java

public OctopusMetaModelDataSource(MetaDataSource metaDataSource) {
    super(metaDataSource);

    LOG.debug("create OctopusMetaModelDataSource. dataSourceName: " + metaDataSource.getName());

    JSONParser jsonParser = new JSONParser();
    try {//from  w w w. j av a2  s. c o  m
        connectionInfo = (JSONObject) jsonParser.parse(metaDataSource.getConnectionString());
    } catch (ParseException ignore) {
        /*
         * NOTE: parse() never fail, because ADD DATASOURCE... succeeded.
         *       This assumption is NOT preferable.
         */
    }

    ImmutableMap.Builder<String, Schema> builder = ImmutableMap.builder();
    for (MetaSchema metaSchema : metaDataSource.getSchemas())
        builder.put(metaSchema.getName(), new OctopusMetaModelSchema(metaSchema, this));
    setSubSchemaMap(builder.build());
}

From source file:animalclient.GoogleClient.java

public GoogleClient(String destination) throws MalformedURLException, IOException, ParseException {
    url = new URL("https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vienna&destinations="
            + destination);/*from   w w  w.j av  a 2s. co m*/
    conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("GET");
    reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

    while ((line = reader.readLine()) != null) {
        outputString += line;
    }
    //        System.out.println(outputString);

    JSONObject responseObject = (JSONObject) new JSONParser().parse(outputString);
    String rows = responseObject.get("rows").toString();

    //        System.out.println("outputString=" + outputString);
    //        System.out.println("rows=" + rows.substring(1, rows.length()-1));

    JSONObject responseObjectRows = (JSONObject) new JSONParser().parse(rows.substring(1, rows.length() - 1));
    String elements = responseObjectRows.get("elements").toString();
    //        System.out.println("elements=" + elements.substring(1, elements.length()-1));

    JSONObject responseObjectElements = (JSONObject) new JSONParser()
            .parse(elements.substring(1, elements.length() - 1));
    String distance = responseObjectElements.get("distance").toString();
    //        System.out.println("distance=" + distance.substring(1, distance.length()-1));        

    JSONObject responseObjectDistance = (JSONObject) new JSONParser().parse(distance);
    distanceMeter = responseObjectDistance.get("value").toString();
    //        System.out.println("value=" + distanceMeter);
}