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:com.modeln.batam.connector.wrapper.TestEntry.java

@SuppressWarnings("unchecked")
public static TestEntry fromJSON(JSONObject obj) {
    String id = (String) obj.get("id");
    String buildId = (String) obj.get("build_id");
    String buildName = (String) obj.get("build_name");
    String reportId = (String) obj.get("report_id");
    String reportName = (String) obj.get("report_name");
    String name = (String) obj.get("name");
    String description = (String) obj.get("description");
    String startDate = (String) obj.get("start_date");
    String endDate = (String) obj.get("end_date");
    String status = (String) obj.get("status");
    boolean override = (Boolean) obj.get("override");

    List<Pair> criterias = new ArrayList<Pair>();
    JSONArray criteriasArray = (JSONArray) obj.get("criterias");
    if (criteriasArray != null) {
        for (Iterator<JSONObject> it = criteriasArray.iterator(); it.hasNext();) {
            JSONObject criteria = it.next();
            criterias.add(Pair.fromJSON(criteria));
        }/*from  w w w .  j a v a  2  s .c o m*/
    }

    List<String> tags = new ArrayList<String>();
    JSONArray tagsArray = (JSONArray) obj.get("tags");
    if (tagsArray != null) {
        for (Iterator<String> it = tagsArray.iterator(); it.hasNext();) {
            String tag = it.next();
            tags.add(tag);
        }
    }

    List<Step> steps = new ArrayList<Step>();
    JSONArray stepsArray = (JSONArray) obj.get("steps");
    if (stepsArray != null) {
        for (Iterator<JSONObject> it = stepsArray.iterator(); it.hasNext();) {
            JSONObject step = it.next();
            steps.add(Step.fromJSON(step));
        }
    }

    String log = (String) obj.get("log");

    boolean isCustomFormatEnabled = (Boolean) obj.get("isCustomFormatEnabled") == null ? false
            : (Boolean) obj.get("isCustomFormatEnabled");
    String customFormat = (String) obj.get("customFormat");
    String customEntry = (String) obj.get("customEntry");

    return new TestEntry(id, buildId, buildName, reportId, reportName, name, description,
            startDate == null ? null : new Date(Long.valueOf(startDate)),
            endDate == null ? null : new Date(Long.valueOf(endDate)), status, criterias, tags, steps, log,
            override, isCustomFormatEnabled, customFormat, customEntry);
}

From source file:halive.shootinoutside.common.core.game.map.GameMap.java

public static GameMap loadGameMapFromJSONString(String s) throws ParseException {
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(s);
    if (obj instanceof JSONObject) {
        JSONObject in = (JSONObject) obj;
        GameMap map = new GameMap();
        //Verify Validity
        if (!in.get("type").equals("soTileMap"))
            return null;
        //TODO Implement Determination of the Deserializer depending on the version
        //Load Width/Height and Mapname
        map.mapName = in.get("mapName").toString();
        map.width = (int) (long) in.get("width");
        map.height = (int) (long) in.get("height");
        //Load the Map Data
        byte[] mapData = Base64.getDecoder().decode((String) in.get("mapDataB64"));
        map.loadTilesFromByteArray(mapData);
        //Load the Spawnpositions
        int amtTeams = (int) (long) in.get("amtTeams");
        if (amtTeams != Teams.values().length) {
            return null;
        }/*  www . j av  a2  s .  c  o  m*/
        for (int i = 0; i < amtTeams; i++) {
            JSONObject o = (JSONObject) in.get("spawn_team_" + i);
            int len = (int) (long) o.get("length");
            for (int j = 0; j < len; j++) {
                JSONObject oj = (JSONObject) o.get("" + j);
                map.spawnPositions[i].add(Vector2D.fromJSONObject(oj));
            }
        }
        //Load the ItemLayer
        map.itemLayer = ItemLayer.fromJSONObject((JSONObject) in.get("itemLayer"));
        //Read the Image
        map.textureSheet = Base64.getDecoder().decode(in.get("tileImageB64").toString());
        return map;
    } else {
        return null;
    }
}

From source file:IrqaQuery.java

public static void batch_query(String basedir, String indexpath) throws Exception {
    indexpath = basedir + "/index_all" + indexpath + "/";
    String stopwords = basedir + "/stopwords.txt";
    IrqaQuery lp = new IrqaQuery();

    JSONParser parser = new JSONParser();
    JSONArray questions = (JSONArray) parser.parse(new FileReader(basedir + "/data/questions.json"));

    long startTime = System.currentTimeMillis();
    int answercount = 0;
    int questioncount = 0;
    for (Object o : questions) {
        JSONObject q = (JSONObject) o;

        String query = (String) q.get("question");
        String gold_id = (String) q.get("paragraph_id");

        List<Document> docs = lp.query(indexpath, stopwords, query, 5, "BM25");

        questioncount++;//  w ww  .j av  a 2s  . c  o  m
        for (Document d : docs) {
            String docid = d.get("docid");

            if (docid.equals(gold_id)) {
                //                    System.out.println(docid);
                answercount = answercount + 1;
                break;
            }
        }
        if (questioncount % 1000 == 0) {
            long midtime = System.currentTimeMillis() - startTime;

            System.out.format("[%d] midtime=%f\n", questioncount, midtime / 1000.0);
        }
    }
    System.out.format("acc=%f\t%d\t%d\n", answercount * 1.0 / questioncount * 100, answercount, questioncount);
    long estimatedTime = System.currentTimeMillis() - startTime;
    System.out.println(estimatedTime / 1000.0);
}

From source file:at.ait.dme.yuma.suite.apps.core.server.annotation.JSONAnnotationHandler.java

public static ArrayList<Annotation> parseAnnotations(String json) {
    ArrayList<Annotation> annotations = new ArrayList<Annotation>();
    JSONArray jsonArray = (JSONArray) JSONValue.parse(json);

    if (jsonArray == null)
        return annotations;

    for (Object obj : jsonArray) {
        JSONObject jsonObj = (JSONObject) obj;
        Annotation annotation;/*w w  w .  j  av a 2  s  . c o m*/

        MediaType type = MediaType.valueOf(((String) jsonObj.get(KEY_MEDIA_TYPE)).toUpperCase());
        String fragment = (String) jsonObj.get(KEY_FRAGMENT);
        if (type == MediaType.IMAGE || type == MediaType.MAP) {
            annotation = new ImageAnnotation();

            if ((fragment != null) && (!fragment.isEmpty())) {
                SVGFragmentHandler svg = new SVGFragmentHandler();
                try {
                    annotation.setFragment(svg.toImageFragment((String) jsonObj.get(KEY_FRAGMENT)));
                } catch (IOException e) {
                    logger.warn("Could not parse image fragment: " + e.getMessage());
                }
            }
        } else if (type == MediaType.AUDIO) {
            annotation = new AudioAnnotation();

            if ((fragment != null) && (!fragment.isEmpty())) {
                AudioFragmentHandler afh = new AudioFragmentHandler();
                annotation.setFragment(afh.parseAudioFramgent(fragment));
            }

        } else {
            throw new RuntimeException("Unsupported annotation type: " + type.name());
        }

        annotation.setId((String) jsonObj.get(KEY_ID));
        annotation.setParentId((String) jsonObj.get(KEY_PARENT_ID));
        annotation.setRootId((String) jsonObj.get(KEY_ROOT_ID));
        annotation.setObjectUri((String) jsonObj.get(KEY_OBJECT_URI));
        annotation.setCreated(new Date((Long) jsonObj.get(KEY_CREATED)));
        annotation.setLastModified(new Date((Long) jsonObj.get(KEY_LAST_MODIFIED)));
        annotation.setCreatedBy(parseUser((JSONObject) jsonObj.get(KEY_CREATED_BY)));
        annotation.setTitle((String) jsonObj.get(KEY_TITLE));
        annotation.setText((String) jsonObj.get(KEY_TEXT));
        annotation.setMediaType(type);

        String scope = (String) jsonObj.get(KEY_SCOPE);
        if (scope != null) {
            annotation.setScope(Scope.valueOf(scope.toUpperCase()));
        } else {
            annotation.setScope(Scope.PUBLIC);
        }

        JSONArray jsonTags = (JSONArray) jsonObj.get(KEY_TAGS);
        if (jsonTags != null)
            annotation.setTags(parseSemanticTags(jsonTags));

        JSONArray jsonReplies = (JSONArray) jsonObj.get(KEY_REPLIES);
        if (jsonReplies != null) {
            ArrayList<Annotation> replies = parseAnnotations(jsonReplies.toString());
            annotation.setReplies(replies);
        }

        annotations.add(annotation);
    }
    return annotations;
}

From source file:kltn.geocoding.Geocoding.java

private static Geometry getBoundary(String s)
        throws MalformedURLException, IOException, org.json.simple.parser.ParseException {
    String link = "https://maps.googleapis.com/maps/api/geocode/json?&key=AIzaSyALCgmmer3Cht-mFQiaJC9yoWdSqvfdAiM";
    link = link + "&address=" + URLEncoder.encode(s);
    URL url = new URL(link);
    HttpsURLConnection httpsCon = (HttpsURLConnection) url.openConnection();
    InputStream is = httpsCon.getInputStream();
    StringWriter writer = new StringWriter();
    IOUtils.copy(is, writer, "UTF-8");

    String jsonString = writer.toString();
    JSONParser parse = new JSONParser();
    Object obj = parse.parse(jsonString);
    JSONObject jsonObject = (JSONObject) obj;
    System.out.println(s);//from   w w w. j  a v  a2 s .  c o  m
    System.out.println(jsonObject.toJSONString());
    JSONArray resultArr = (JSONArray) jsonObject.get("results");
    Object resultObject = parse.parse(resultArr.get(0).toString());
    JSONObject resultJsonObject = (JSONObject) resultObject;

    Object geoObject = parse.parse(resultJsonObject.get("geometry").toString());
    JSONObject geoJsonObject = (JSONObject) geoObject;

    if (!geoJsonObject.containsKey("bounds")) {
        return null;
    }
    Object boundObject = parse.parse(geoJsonObject.get("bounds").toString());
    JSONObject boundJsonObject = (JSONObject) boundObject;
    //        System.out.println(boundJsonObject.toJSONString());

    Object southwest = parse.parse(boundJsonObject.get("southwest").toString());
    JSONObject southwestJson = (JSONObject) southwest;
    String southwestLat = southwestJson.get("lat").toString();
    String southwestLong = southwestJson.get("lng").toString();

    Object northeast = parse.parse(boundJsonObject.get("northeast").toString());
    JSONObject northeastJson = (JSONObject) northeast;
    String northeastLat = northeastJson.get("lat").toString();
    String northeastLong = northeastJson.get("lng").toString();

    String polygon = "POLYGON((" + southwestLong.trim() + " " + northeastLat.trim() + "," + northeastLong.trim()
            + " " + northeastLat.trim() + "," + northeastLong.trim() + " " + southwestLat.trim() + ","
            + southwestLong.trim() + " " + southwestLat.trim() + "," + southwestLong.trim() + " "
            + northeastLat.trim() + "))";
    Geometry geo = wktToGeometry(polygon);
    return geo;
}

From source file:com.aerospike.load.Parser.java

public static Object getJsonObject(JSONObject jobj, String key) {
    Object obj = null;//from  w  w  w .ja  va  2  s. co m
    if ((obj = jobj.get(key)) == null) {
        log.warn("\"" + key + "\"  Key is missing in config file");
    }
    return obj;
}

From source file:IrqaQuery.java

public static void get_sentence_from_json(JSONArray raw_list, String question, String docid, BufferedWriter out)
        throws Exception {
    for (Object o : raw_list) {
        JSONObject rl = (JSONObject) o;

        String query = (String) rl.get("question");
        String pid = (String) rl.get("paragraph_id");

        if (query.compareTo(question) == 0) {

        }/*from   ww  w .  ja v a2s.  c  o m*/

        if (pid.compareTo(docid) == 0 && query.compareTo(question) == 0) {
            // if docid is matched
            // get candidate index
            List<Integer> candidate_list = new ArrayList<Integer>();
            //                if (rl.get("candidates").toString().length()>1){
            //                System.out.println(rl.get("candidates").toString());
            String[] candidates = rl.get("candidates").toString().split(",");
            for (String cand : candidates) {
                //                    System.out.println(cand);
                //                    System.out.println(rl.get("candidates").toString());
                candidate_list.add(Integer.parseInt(cand.replace(" ", "")) - 1);
            }
            //                }

            // print with candidate 0/1
            int index_of_sen = 0;
            for (Object sen : (JSONArray) rl.get("sentences")) {
                int zero_one = 0;
                for (int cand : candidate_list) {
                    if (index_of_sen == cand)
                        zero_one = 1;
                }
                String out_format = String.format("%s\t%s\t%d\n", question, sen, zero_one);
                out.write(out_format);
                index_of_sen++;
            }
        } else {
            // print with candidate 0
            for (Object sen : (JSONArray) rl.get("sentences")) {
                //                    System.out.format("%s\t%s\t%d\n", question, sen, 0);
                String out_format = String.format("%s\t%s\t%d\n", question, sen, 0);
                out.write(out_format);
            }
        }

    }
}

From source file:com.netbase.insightapi.bestpractice.TopicDownloader.java

protected static Object getDocProperty(Object d, String propName) {
    JSONObject doc = (JSONObject) d;
    JSONObject properties = (JSONObject) doc.get("properties");
    return (properties.get(propName));
}

From source file:com.p000ison.dev.copybooks.util.Helper.java

public static ArrayList<String> fromJSONStringtoList(String key, String string) {

    if (string != null && !string.isEmpty()) {
        ArrayList<String> out = new ArrayList<String>();

        JSONObject flags = (JSONObject) JSONValue.parse(string);

        if (flags != null) {
            for (Object keys : flags.keySet()) {
                try {

                    if (keys.equals(key)) {
                        JSONArray list = (JSONArray) flags.get(keys);

                        if (list != null) {
                            for (Object k : list) {
                                out.add(k.toString());
                            }/*  ww  w  .  j av a2  s. co  m*/
                        }
                    }

                } catch (Exception ex) {
                    CopyBooks.debug(String.format("Failed reading flag: %s", keys));
                    CopyBooks.debug(String.format("Value: %s", flags.get(key)));
                    CopyBooks.debug(null, ex);
                }
            }
        }
        return out;
    }
    return null;
}

From source file:it.polimi.logging.LogMessageUtils.java

public static Type getEntityType(String message) {
    JSONParser parser = new JSONParser();
    JSONObject jsonMsg;
    String type = "";
    try {//  w ww  .jav  a 2 s . co  m
        jsonMsg = (JSONObject) parser.parse(message);
        type = (String) jsonMsg.get(JsonStrings.ENTITY_TYPE);
        return Type.valueOf(type);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}