Example usage for org.json.simple JSONObject get

List of usage examples for org.json.simple JSONObject get

Introduction

In this page you can find the example usage for org.json.simple JSONObject get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:ly.stealth.punxsutawney.Marathon.java

public static List<String> getEndpoints(String app) throws IOException {
    @SuppressWarnings("unchecked")
    List<JSONObject> tasks = getTasks(app);
    if (tasks == null)
        return Collections.emptyList();

    List<String> endpoints = new ArrayList<>();
    for (JSONObject task : tasks)
        endpoints.add(task.get("host") + ":" + ((JSONArray) task.get("ports")).get(0));

    return endpoints;
}

From source file:br.net.fabiozumbi12.RedProtect.hooks.MojangUUIDs.java

public static String getUUID(String player) {
    try {/*  w  ww .j  a  v  a 2  s .c  o m*/
        URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + player);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String line = in.readLine();
        if (line == null) {
            return null;
        }
        JSONObject jsonProfile = (JSONObject) new JSONParser().parse(line);
        String name = (String) jsonProfile.get("id");
        return toUUID(name);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:ly.stealth.punxsutawney.Marathon.java

public static void startApp(App app) throws IOException, InterruptedException {
    sendRequest("/v2/apps", "POST", app.toJson());

    for (;;) {/*from   w  ww. j  av  a 2  s  .  co  m*/
        @SuppressWarnings("unchecked")
        List<JSONObject> tasks = getTasks(app.id);
        if (tasks == null)
            throw new IllegalStateException("App " + app.id + " not found");

        int started = 0;
        for (JSONObject task : tasks)
            if (task.get("startedAt") != null)
                started++;

        if (started == app.instances)
            break;
        Thread.sleep(1000);
    }
}

From source file:cloudclient.Client.java

public static void batchReceiveResp(BufferedReader in) throws IOException, ParseException {
    BufferedWriter bw = new BufferedWriter(new FileWriter("result.txt"));

    JSONParser parser = new JSONParser();

    String message;//w w w  .ja  v  a  2s  .c  o m
    while ((message = in.readLine()) != null) {
        //System.out.println(message);
        JSONArray responseList = (JSONArray) parser.parse(message);

        for (int i = 0; i < responseList.size(); i++) {
            JSONObject response = (JSONObject) responseList.get(i);
            bw.write(response.get("URL").toString());
            bw.newLine();
        }
    }

    bw.close();

}

From source file:com.speedment.examples.social.JSONUser.java

public static List<JSONUser> parse(String json) {
    final JSONObject container = (JSONObject) JSONValue.parse(json);
    final JSONArray array = (JSONArray) container.get("users");
    final List<JSONUser> users = new ArrayList<>();

    array.stream().forEach(u -> {/*from  www  .j a v a 2  s. c o m*/
        users.add(parse((JSONObject) u));
    });

    return users;
}

From source file:luceneprueba.utils.FileParser.java

static public void createFilesFromJSONArray() throws IOException {
    File dir = new File("files/input");
    File[] files = dir.listFiles();

    if (files == null) {
        System.out.println("No existe la carpeta \'input\' dentro de la carpeta files.");
        return;/* w w w  . j av  a  2 s .c o  m*/
    }

    if (files.length == 0) {
        System.out.println("No hay ningun archivo en la carpeta \'input\' para ser indexado");
        return;
    }

    BufferedReader br;
    String fileContent;
    JSONArray jsonArray = null;
    JSONParser jsonParser = new JSONParser();
    int i = 1;
    FileWriter datosReviews = null;
    try {
        datosReviews = new FileWriter("files/output/datos_reviews.txt");
    } catch (IOException ex) {
        ex.printStackTrace(System.out);
    }
    for (File file : files) {
        if (file.isFile() && file.canRead() && file.getName().endsWith(".txt")) {
            System.out.println("Leyendo el archivo: " + file.getName());
            FileWriter contentReviews;
            try {
                br = new BufferedReader(new FileReader(file));
                fileContent = br.readLine();
                jsonArray = (JSONArray) jsonParser.parse(fileContent);
                Iterator it = jsonArray.iterator();
                DecimalFormat formato = new DecimalFormat("000000");
                while (it.hasNext()) {
                    JSONObject json = (JSONObject) it.next();
                    if (json.get("Genre") != null && json.get("Date") != null) {
                        contentReviews = new FileWriter(
                                "files/output/clasificador/review_clasificador_" + formato.format(i) + ".txt");
                        datosReviews.write(Integer.toString(i) + "_" + (String) json.get("Date") + "_"
                                + (String) json.get("Genre") + "_" + (String) json.get("Score") + "\n");
                        contentReviews.write(Integer.toString(i) + " " + (String) json.get("Review"));
                        i++;
                        contentReviews.close();
                    }
                }
                br.close();
            } catch (FileNotFoundException ex) {
                ex.printStackTrace(System.out);
            } catch (IOException | ParseException ex) {
                ex.printStackTrace(System.out);
            }
        }
    }
    datosReviews.close();
}

From source file:mysynopsis.JSONReader.java

public static void readData() throws FileNotFoundException, IOException, ParseException {

    try {/*from   ww  w. j a v a  2s.  c  o  m*/
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(new FileReader("data.json"));
        JSONObject read;
        read = (JSONObject) obj;

        name = (String) read.get("Name");
        initial = (String) read.get("Initial");
        biog = (String) read.get("Bio");
        designation = (String) read.get("Designation");
        dept = (String) read.get("Department");
        university = (String) read.get("University");
        universityAddress = (String) read.get("University_Address");
        office = (String) read.get("Office");
        officehours = (String) read.get("Ohours");
        phone = (String) read.get("Phone");
        email = (String) read.get("Email");
        resumelink = (String) read.get("Resume_Link");
        education = (String) read.get("Educational");
        professional = (String) read.get("Professional");
        awards = (String) read.get("Awards");

        imgExtension = (String) read.get("Image_Ext");
        imgString = (String) read.get("Image_String");

        /*JSONArray education = (JSONArray) read.get("Education");
                
        for(int i=0;i<8;i++) {
                
        educ[i] = (String) education.get(i);
                
        }*/
        JSONArray ftpinfo = (JSONArray) read.get("Server_Information");

        server = (String) ftpinfo.get(0);
        user = (String) ftpinfo.get(1);
        dir = (String) ftpinfo.get(2);
    } catch (IOException | ParseException e) {

        JOptionPane.showMessageDialog(null, "Something went wrong. Please re-run the software.");
    }
}

From source file:com.articulate.sigma.nlp.pipeline.CorefTest.java

@Parameters(name = "<{0}> {1}  {2}")
public static Collection<Object[]> prepare() {

    return JsonReader.transform("QATests1/corefTests.json", (JSONObject jo) -> {
        String fileName = (String) jo.get("file");
        Long sentence = (Long) jo.get("sentence");
        Long sentenceA = sentence != null ? sentence : (Long) jo.get("sentenceA");
        Long sentenceB = sentence != null ? sentence : (Long) jo.get("sentenceB");

        String valueA = (String) jo.get("valueA");
        String valueB = (String) jo.get("valueB");
        return new Object[] { fileName,
                valueA == null ? CorefParam.of(sentenceA, (Long) jo.get("indexA"))
                        : CorefParam.of(sentenceA, valueA),
                valueB == null ? CorefParam.of(sentenceB, (Long) jo.get("indexB"))
                        : CorefParam.of(sentenceB, valueB) };
    });//from  w  w w  .  j av  a 2s  . c  o m
}

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  w w .j a  v  a2  s  .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:com.AandC.GemsCraft.Configuration.ConfigKey.java

public static int getPort() {
    try {//w  w w  .j  a va2  s .  c  o m
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(new FileReader("/sdcard/GemsCraft/config.json"));
        JSONObject jsonObject = (JSONObject) obj;
        port = jsonObject.get("Port");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return port;
}