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:interfaceTisseoWS.ST4.java

public final void init() throws ParseException, IOException, URISyntaxException {
    RequestJCDecaux r = new RequestJCDecaux();
    JSONParser parser = new JSONParser();

    r.setPathURIB("/vls/v1/stations");

    Object obj = parser.parse(r.request());
    JSONArray array = (JSONArray) obj;/*from  www .j  a  v  a 2s .c  o m*/

    int nbStations = array.size();
    DefaultListModel lm = new DefaultListModel();
    for (int i = 0; i < nbStations; i++) {
        stations.add(new Station((JSONObject) array.get(i)));
        lm.addElement(stations.get(i).getName());
    }
    listeStations.setModel(lm);
}

From source file:org.jboss.test.arquillian.ce.sso.support.Client.java

public String getToken(String username, String password) throws Exception {
    Map<String, String> params = new HashMap<>();
    params.put("username", username);
    params.put("password", password);
    params.put("grant_type", "password");
    params.put("client_id", "admin-cli");

    setParams(params);//from   w  w  w .  ja va  2s .  c  om
    String result = post("auth/realms/master/protocol/openid-connect/token");

    assertFalse(result.contains("error_description"));
    assertTrue(result.contains("access_token"));

    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = (JSONObject) jsonParser.parse(result);
    String accessToken = (String) jsonObject.get("access_token");

    setParams(null);

    return accessToken;
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.algorithm.VehicleStatusTestCase.java

@Test
public void testCase03() throws ParseException {
    String status = "{\"vehicle.id\":\"c2345527-2796-4ea9-b500-d842d6f2b638\",\"state\":\"suspended\",\"latitude\":48.82211311,\"longitude\":18.04076076,\"altitude\":38.0,"
            + "\"tolerance\":8.2,\"actions\":[\"temperature\"]}";
    @SuppressWarnings("serial")
    Set<String> expectedSensors = new HashSet<String>() {
        {/*from  w  w  w  .  j av a  2  s  . c  om*/
            add("temperature");
        }
    };

    JSONParser parser = new JSONParser();
    VehicleStatus s = new VehicleStatus((JSONObject) parser.parse(status));
    Assert.assertEquals("c2345527-2796-4ea9-b500-d842d6f2b638", s.getId());
    Assert.assertEquals("suspended", s.getState().toString().toLowerCase());
    Assert.assertEquals(48.82211311, s.getPosition().getLatitude(), 1E-9);
    Assert.assertEquals(18.04076076, s.getPosition().getLongitude(), 1E-9);
    Assert.assertEquals(38.0, s.getPosition().getAltitude(), 1E-9);
    Assert.assertEquals(8.2, s.getTolerance(), 1E-9);
    Assert.assertTrue(s.getActions().containsAll(expectedSensors));
    Assert.assertTrue(expectedSensors.containsAll(s.getActions()));

    s = new VehicleStatus((JSONObject) parser.parse(s.toJSONString()));
    Assert.assertEquals("c2345527-2796-4ea9-b500-d842d6f2b638", s.getId());
    Assert.assertEquals("suspended", s.getState().toString().toLowerCase());
    Assert.assertEquals(48.82211311, s.getPosition().getLatitude(), 1E-9);
    Assert.assertEquals(18.04076076, s.getPosition().getLongitude(), 1E-9);
    Assert.assertEquals(38.0, s.getPosition().getAltitude(), 1E-9);
    Assert.assertEquals(8.2, s.getTolerance(), 1E-9);
    Assert.assertTrue(s.getActions().containsAll(expectedSensors));
    Assert.assertTrue(expectedSensors.containsAll(s.getActions()));
}

From source file:me.bobbyallen.jlikkle.jLikkle.java

/**
 * Decodes the JSON string to a usable 'data' section JSONObject
 *
 * @return JSONObject//from   w  w w .j a v  a2s  .  com
 * @throws ParseException
 */
private JSONObject responseDecodeData() throws ParseException {
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = (JSONObject) jsonParser.parse(this.response); // Complete response.
    JSONObject dataObject = (JSONObject) jsonParser.parse(jsonObject.get("data").toString()); // The 'data' section.
    return dataObject;
}

From source file:me.bobbyallen.jlikkle.jLikkle.java

/**
 * Decodes the JSON data section to a usable 'stats' JSONObject
 *
 * @return JSONObject// w ww.  ja  v a2s .  c o m
 * @throws ParseException
 */
private JSONObject responseDecodeStats(JSONObject dataObject) throws ParseException {
    JSONParser jsonParser = new JSONParser();
    JSONObject statsObject = (JSONObject) jsonParser.parse(dataObject.get("stats").toString()); // The 'data.stats' section.
    return statsObject;
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.algorithm.VehicleStatusTestCase.java

@Test
public void testCase01() throws ParseException {
    String status = "{\"vehicle.id\":\"b2345527-2796-4ea9-b500-d842d6f2b638\",\"state\":\"active\",\"latitude\":47.82211311,\"longitude\":13.04076076,\"altitude\":30.0,"
            + "\"tolerance\":1.2,\"actions\":[\"photo\"]}";
    @SuppressWarnings("serial")
    Set<String> expectedSensors = new HashSet<String>() {
        {/*from   w w  w.j  a v  a  2  s  . c  o  m*/
            add("photo");
        }
    };

    JSONParser parser = new JSONParser();
    VehicleStatus s = new VehicleStatus((JSONObject) parser.parse(status));
    Assert.assertEquals("b2345527-2796-4ea9-b500-d842d6f2b638", s.getId());
    Assert.assertEquals("active", s.getState().toString().toLowerCase());
    Assert.assertEquals(47.82211311, s.getPosition().getLatitude(), 1E-9);
    Assert.assertEquals(13.04076076, s.getPosition().getLongitude(), 1E-9);
    Assert.assertEquals(30.0, s.getPosition().getAltitude(), 1E-9);
    Assert.assertEquals(1.2, s.getTolerance(), 1E-9);
    Assert.assertTrue(s.getActions().containsAll(expectedSensors));
    Assert.assertTrue(expectedSensors.containsAll(s.getActions()));
    System.out.println("testCase01-1: " + s.toJSONString());

    s = new VehicleStatus((JSONObject) parser.parse(s.toJSONString()));
    Assert.assertEquals("b2345527-2796-4ea9-b500-d842d6f2b638", s.getId());
    Assert.assertEquals("active", s.getState().toString().toLowerCase());
    Assert.assertEquals(47.82211311, s.getPosition().getLatitude(), 1E-9);
    Assert.assertEquals(13.04076076, s.getPosition().getLongitude(), 1E-9);
    Assert.assertEquals(30.0, s.getPosition().getAltitude(), 1E-9);
    Assert.assertEquals(1.2, s.getTolerance(), 1E-9);
    Assert.assertTrue(s.getActions().containsAll(expectedSensors));
    Assert.assertTrue(expectedSensors.containsAll(s.getActions()));
}

From source file:edu.pdx.konstan2.PortlandLive.StopsFactory.java

public Stop(String jsonString) {
    try {/*from   w w w  .ja v a 2s.  co m*/
        JSONParser parser = new JSONParser();
        JSONObject jobj = (JSONObject) parser.parse(jsonString);
        jsonRepresntation = jobj;
        parse(jsonRepresntation);
    } catch (Exception e) {
    }

}

From source file:hoot.services.controllers.ingest.RasterToTilesResourceTest.java

@Test
@Category(UnitTest.class)
public void TestIngestOSMResource() throws Exception {
    String processScriptName = RASTER_TO_TILES;
    Assert.assertNotNull(processScriptName);
    Assert.assertTrue(!processScriptName.isEmpty());

    RasterToTilesService rts = new RasterToTilesService();

    JSONObject oExpected = new JSONObject();
    oExpected.put("caller", "RasterToTilesService");
    oExpected.put("exec", processScriptName);

    JSONArray params = new JSONArray();
    JSONObject param = new JSONObject();
    param.put("RASTER_OUTPUT_DIR", tileServerPath);
    params.add(param);//from   w  w w.  ja v  a2  s .  c  om

    param = new JSONObject();
    param.put("INPUT", "test");
    params.add(param);

    param = new JSONObject();
    param.put("ZOOM_LIST", "0-1 2-3");
    params.add(param);

    param = new JSONObject();
    param.put("RASTER_SIZE", "500");
    params.add(param);

    param = new JSONObject();
    param.put("MAP_ID", "1");
    params.add(param);

    oExpected.put("params", params);

    oExpected.put("exectype", "make");
    oExpected.put("erroraswarning", "true");

    Method createCommandMethod = RasterToTilesService.class.getDeclaredMethod("createCommand", String.class,
            String.class, int.class, long.class);

    createCommandMethod.setAccessible(true);

    String actual = (String) createCommandMethod.invoke(rts, "test", "0-1 2-3", 500, 1);

    JSONParser parser = new JSONParser();
    JSONObject actualObj = (JSONObject) parser.parse(actual);

    Assert.assertEquals(oExpected, actualObj);
}

From source file:DOMIC.EncodeJson.java

public EncodeJson(String JsonText) {

    JSONParser jsonParser = new JSONParser();

    try {/*from  w w w. j a  v a  2  s .c o  m*/

        JSONObject jsonObject = (JSONObject) jsonParser.parse(JsonText);

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

        for (int i = 0; i < test.size(); i++) {

            JSONArray questionBlock;
            this.questionBlocks.add(new QuestionBlock());
            questionBlock = (JSONArray) test.get(i);

            for (int j = 0; j < questionBlock.size(); j++) {

                HashMap questions = (HashMap) questionBlock.get(j);

                if (questions.get("-oa") != null) {

                    this.questionBlocks.get(i).questions.add(new Question((String) questions.get("-qu")));
                    JSONArray answerList = null;
                    answerList = (JSONArray) questions.get("-oa");

                    this.questionBlocks.get(i).questions.get(j).addAnswer(true, (String) answerList.get(0));

                }
                if (questions.get("-sa") != null) {

                    this.questionBlocks.get(i).questions.add(new Question((String) questions.get("-qu")));
                    JSONArray answerList = null;
                    answerList = (JSONArray) questions.get("-sa");
                    for (int k = 0; k < answerList.size(); k++) {
                        this.questionBlocks.get(i).questions.get(j).addAnswer(true, (String) answerList.get(k));
                    }

                }

                if (questions.get("-ma") != null) {

                    this.questionBlocks.get(i).questions.add(new Question((String) questions.get("-qu")));
                    JSONArray answerList = null;

                    answerList = (JSONArray) questions.get("-ma");
                    JSONArray trueAnswer = (JSONArray) answerList.get(0);
                    JSONArray falseAnswer = (JSONArray) answerList.get(1);

                    for (int k = 0; k < trueAnswer.size(); k++) {
                        this.questionBlocks.get(i).questions.get(j).addAnswer(true, (String) trueAnswer.get(k));

                    }
                    for (int k = 0; k < falseAnswer.size(); k++) {
                        this.questionBlocks.get(i).questions.get(j).addAnswer(false,
                                (String) falseAnswer.get(k));

                    }

                }

            }

        }

        System.out.println("");

    } catch (ParseException e) {
        e.printStackTrace();
    }

}

From source file:net.phyloviz.goeburst.tree.GOeBurstMSTItemFactory.java

@Override
public ProjectItem loadData(DataSet dataset, TypingData<? extends AbstractProfile> td, String directory,
        String filename, AbstractDistance ad, int level) {
    GOeBurstMSTSchemaValidator validator = new GOeBurstMSTSchemaValidator();
    try {/*from  w  ww . ja  va  2s .co m*/
        if (!validator.validate(directory, filename)) {
            return null;
        }
    } catch (IOException e) {
        Exceptions.printStackTrace(e);
    }

    GOeBurstMSTResult goeburstItem = null;

    try {
        FileReader reader = new FileReader(new File(directory, filename));

        JSONParser parser = new JSONParser();
        JSONObject json;
        json = (JSONObject) parser.parse(reader);

        JSONArray nodesArray = (JSONArray) json.get("nodes");
        JSONArray edgesArray = (JSONArray) json.get("edges");

        Map<String, GOeBurstNode> profiles = new HashMap<>();
        for (Iterator<? extends AbstractProfile> tdIt = td.iterator(); tdIt.hasNext();) {
            GOeBurstNode node = new GOeBurstNode(tdIt.next());
            profiles.put(node.getID(), node);
        }

        Map<Integer, GOeBurstNode> nodes = getNodes(profiles, nodesArray);

        Collection<Edge<GOeBurstNode>> tree = createEdges(edgesArray, nodes);

        OutputPanel op = new OutputPanel(dataset.toString() + ": goeBURST Full MST");
        goeburstItem = new GOeBurstMSTResult(dataset, tree, ad, op);

    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
    return goeburstItem;
}