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:net.duckling.falcon.xss.JSONConfig.java

private static void addProtocols(Whitelist whitelist, JSONObject config) {
    JSONObject protocolsJson = (JSONObject) config.get("protocols");
    for (String key : protocolsJson.keySet()) {
        String[] pair = key.split("\\.");
        if (pair.length == 2) {
            JSONArray protocols = (JSONArray) protocolsJson.get(key);
            for (Object p : protocols) {
                whitelist.addProtocols(pair[0], pair[1], (String) p);
            }/*from w  ww  . jav a2s .  c  o m*/
        }
    }
}

From source file:naftoreiclag.villagefive.SaveLoad.java

public static World load(Node rootNode, AssetManager assetManager) throws IOException, ParseException {
    World world = new World(rootNode, assetManager);

    JSONParser parser = new JSONParser();

    File file = new File("saves/save.json");
    FileReader fr = new FileReader(file);
    JSONObject root = (JSONObject) parser.parse(fr);
    JSONObject worldj = (JSONObject) root.get("world");

    System.out.println(worldj);// w  w  w . j  av  a2s  . c o  m

    world.spawnFromJson(worldj);

    return world;
}

From source file:authorship.verification.ReadJSON.java

public static String readJson(String file) {
    JSONParser parser = new JSONParser();
    try {//from w ww  . j  av  a  2 s.com
        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:halive.shootinoutside.common.util.Vector2D.java

public static Vector2D fromJSONObject(JSONObject o) {
    float x = Float.intBitsToFloat((int) (long) o.get("x"));
    float y = Float.intBitsToFloat((int) (long) o.get("y"));
    return new Vector2D(x, y);
}

From source file:com.mtgox.examples.UsageExample.java

public static ApiKeys readApiKeys(String pathToJsonFile) {
    //see https://code.google.com/p/json-simple/wiki/DecodingExamples
    JSONParser parser = new JSONParser();
    ApiKeys apiKeys = null;/*from   w w w . jav  a  2 s .  c o  m*/
    String apiStr = Utils.readFromFile(pathToJsonFile);
    try {
        JSONObject obj2 = (JSONObject) (parser.parse(apiStr));
        apiKeys = new ApiKeys((String) obj2.get("mtgox_secret_key"), (String) obj2.get("mtgox_api_key"));
    } catch (ParseException ex) {
        System.err.println(ex);
    }
    return apiKeys;
}

From source file:de.hstsoft.sdeep.model.FollowSpawn.java

public static FollowSpawn parse(JSONObject json) {
    FollowSpawn followSpawn = new FollowSpawn();

    JSONObject centerGridPos = (JSONObject) json.get(CENTER_GRID_POS);
    followSpawn.centerGridPos = Position.parseVector(centerGridPos);

    return followSpawn;
}

From source file:featureExtractor.popularityMeasure.java

static double ParseJSON_getScore(String s) throws ParseException {
    JSONObject json = (JSONObject) new JSONParser().parse(s);
    JSONArray results = (JSONArray) json.get("result");
    JSONObject resultObject = (JSONObject) results.get(0);
    return (double) resultObject.get("score");
}

From source file:manager.computerVisionManager.java

public static String getImageDescription(String path) {
    if (json == null) {
        getJson(path);// www . j a va2s.c  o m
    }
    try {
        System.out.println(json.toString());
        JSONArray captions = (JSONArray) json.get("captions");
        JSONObject text = (JSONObject) captions.get(0);
        return text.get("text").toString();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    return "error";
}

From source file:net.jakobnielsen.imagga.convert.ConverterTools.java

public static String getString(String key, Object o) {
    if (key == null || o == null) {
        return null;
    } else if (o instanceof JSONArray) {
        return null; // Maybe throw exception in the future.
    } else if (o instanceof JSONObject) {
        JSONObject jo = (JSONObject) o;
        if (jo.containsKey(key)) {
            return jo.get(key) == null ? null : jo.get(key).toString();
        }/* w  ww .  j  a  v a 2 s  .  co  m*/
    }
    return null;

}

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

private static String mapToString(JSONObject user, String key) {
    return Optional.ofNullable(user.get(key)).map(Object::toString).orElse("");
}