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:de.hstsoft.sdeep.model.GameObject.java

public static GameObject parse(JSONObject json) {
    GameObject gameObject = new GameObject();

    gameObject.name = json.get(NAME).toString();
    gameObject.type = gameObject.name.substring(0, gameObject.name.indexOf("("));

    if (gameObject.type.equals(ItemTypes.SEA_FORT_1) || gameObject.type.equals(ItemTypes.SEA_FORT_2)
            || gameObject.type.equals(ItemTypes.SEA_FORT_3)) {
        gameObject.order = 0;// w ww.j  a  v  a2 s.  c om
    }

    if (gameObject.type.equals(ItemTypes.PALM_TREE) || gameObject.type.equals(ItemTypes.PALM_TREE_1)
            || gameObject.type.equals(ItemTypes.PALM_TREE_2) || gameObject.type.equals(ItemTypes.PALM_TREE_3)
            || gameObject.type.equals(ItemTypes.PALM_TREE_4)) {
        gameObject.order = 0;
    }

    // retVal.displayName = json.get("displayName").toString();

    JSONObject transform = (JSONObject) json.get(TRANSFORM);
    gameObject.localPosition = Position.parseVector((JSONObject) transform.get(LOCAL_POSITION));
    // System.out.println(retVal.localPosition);

    // System.out.println("***** Begin Game Object *****");
    // Iterator<?> iter = json.entrySet().iterator();
    // while (iter.hasNext()) {
    // Map.Entry<?, ?> entry = (Map.Entry<?, ?>) iter.next();
    // System.out.println(entry.getKey());
    // }
    // System.out.println("***** END *****");

    return gameObject;
}

From source file:me.prokopyl.commandtools.migration.UUIDFetcher.java

static public Map<String, UUID> fetch(List<String> names) throws IOException {
    Map<String, UUID> uuidMap = new HashMap<String, UUID>();
    HttpURLConnection connection = createConnection();

    writeBody(connection, names);//w  w  w .java2  s .  co m

    JSONArray array;
    try {
        array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
    } catch (ParseException ex) {
        throw new IOException("Invalid response from server, unable to parse received JSON : " + ex.toString());
    }

    for (Object profile : array) {
        JSONObject jsonProfile = (JSONObject) profile;
        String id = (String) jsonProfile.get("id");
        String name = (String) jsonProfile.get("name");
        uuidMap.put(name, fromMojangUUID(id));
    }

    return uuidMap;
}

From source file:h.scratchpads.list.json.JSONReader.java

public static String[] getScratchpadsForHarvesting(HarvestingDataArchive archive, LogFile logFile) {
    String info;/*from  ww  w  . j  a v a 2 s. c  o  m*/
    String[] scratchpadURLs = null;
    JSONArray arrayJSON = readJSON(HarvesterConfigData.CURRENT_Scratchpads_JSON_URL, logFile);
    if (arrayJSON != null) {
        List<String> urls = new ArrayList<String>();
        info = "The list of current Scratchpads sites contains " + arrayJSON.size() + " URL(s)";
        logFile.write(info);
        System.out.println(info);
        String field_website;
        String field_profile;
        String field_last_node_changed;
        String fieldLastNodeChangedFromArchive;
        boolean wasThereAnyChangeToHarvestingDataArchive = false;
        for (int i = 0; i < arrayJSON.size(); i++) {
            JSONObject jsonObject = (JSONObject) arrayJSON.get(i);
            field_website = (String) jsonObject.get("field_website");
            if (field_website.startsWith("http")) {
                field_profile = (String) jsonObject.get("field_profile");
                if ((field_profile.equalsIgnoreCase("scratchpad_2"))
                        || (field_profile.equalsIgnoreCase("scratchpad_2_migrate"))) {
                    field_last_node_changed = jsonObject.get("field_last_node_changed").toString();
                    fieldLastNodeChangedFromArchive = archive.getValue(field_website);
                    if (!field_last_node_changed.equalsIgnoreCase(fieldLastNodeChangedFromArchive)) {
                        archive.setValue(field_website, field_last_node_changed);
                        wasThereAnyChangeToHarvestingDataArchive = true;
                        urls.add(field_website);
                    }
                }
            }
        }
        // if there was any change to HarvestingDataArchive then save it:
        if (wasThereAnyChangeToHarvestingDataArchive) {
            archive.saveHarvestingData(logFile);
        }
        scratchpadURLs = new String[urls.size()];
        urls.toArray(scratchpadURLs);
    }
    return scratchpadURLs;
}

From source file:com.mobicage.rogerthat.SearchLocation.java

public static SearchLocation fromJSONObject(JSONObject jsonObject) {
    SearchLocation l = new SearchLocation();
    l.address = (String) jsonObject.get("address");
    l.latitude = (Long) jsonObject.get("lat");
    l.longitude = (Long) jsonObject.get("lon");
    return l;/*w  w w. j a v  a 2  s  .com*/
}

From source file:dimensionsorter.DimensionSorter.java

/**
 * @param args the command line arguments
 *//*from   w w  w .  j av  a  2 s .  c om*/
public static void sortDimensions() {

    CloudQueueMessage message = schedulerQueue.retrieveMessage();
    if (message != null) {
        schedulerQueue.deleteMessage(message);
        String json = message.getMessageContentAsString();
        Object obj = JSONValue.parse(json);
        JSONObject jsonObject = (JSONObject) obj;
        datasetName = (String) jsonObject.get("dataset");
        double[] image_descritor_vector = (double[]) jsonObject.get("im_d_v");
        double[] priority_index = (double[]) jsonObject.get("p_i");

        double[] sorted_i_d_v = new double[image_descritor_vector.length];
        for (int i = 0; i < priority_index.length; i++) {
            sorted_i_d_v[i] = (double) image_descritor_vector[priority_index[i]];
        }

        //Send message to the Image Sorter to retrieve the numberOfImageSorterNodes L^{(m)}
        initializeImageSorter();
    }
}

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

public static Message fromJSON(JSONObject json) {

    try {//from  w  ww. j av  a 2  s  . c o m
        MessageType type = MessageType.fromJSON((String) json.get("type"));
        Constructor<? extends Message> constructor = typeMap.get(type).getConstructor(JSONObject.class);
        return constructor.newInstance(json.get("payload"));
    } catch (Exception ex) {
        throw new IllegalArgumentException("Malformed object[" + json.toJSONString() + "]", ex);
    }
}

From source file:net.amigocraft.mpt.command.InfoCommand.java

@SuppressWarnings("unchecked")
public static String[] getPackageInfo(String id) throws MPTException {
    id = id.toLowerCase();/*from w w  w  . j  a v a 2  s .  c o m*/
    if (Main.packageStore.containsKey("packages")) {
        JSONObject packs = (JSONObject) Main.packageStore.get("packages");
        Object pack = packs.get(id);
        if (pack != null) {
            JSONObject jPack = (JSONObject) pack;
            if (jPack.containsKey("name") && jPack.containsKey("description") && jPack.containsKey("version")
                    && jPack.containsKey("url") && jPack.containsKey("repo")) {
                return new String[] { jPack.get("name").toString(), jPack.get("description").toString(),
                        jPack.get("version").toString(), jPack.get("url").toString(),
                        jPack.get("repo").toString(),
                        jPack.containsKey("sha1") ? jPack.get("sha1").toString() : null,
                        jPack.containsKey("installed") ? jPack.get("installed").toString() : null, };
            } else
                throw new MPTException(ERROR_COLOR + "Package definition for " + ID_COLOR + id + ERROR_COLOR
                        + " is malformed! Running " + COMMAND_COLOR + "/mpt update" + ERROR_COLOR
                        + " may correct" + "this.");
        } else
            throw new MPTException(ERROR_COLOR + "Cannot find package " + ID_COLOR + id + ERROR_COLOR + "!");
    } else
        throw new MPTException("Package store is malformed!");
}

From source file:fr.ribesg.bukkit.ncore.updater.FileDescription.java

public static SortedMap<String, FileDescription> parse(final String jsonString) {
    final SortedMap<String, FileDescription> result = new TreeMap<>(new Comparator<String>() {

        @Override//from   ww w .  j a v  a 2  s.co m
        public int compare(final String a, final String b) {
            return -a.compareTo(b);
        }
    });
    final JSONArray array = (JSONArray) JSONValue.parse(jsonString);
    for (final Object o : array.toArray()) {
        final JSONObject object = (JSONObject) o;
        final String fileName = (String) object.get(FILENAME_KEY);
        final String version = VersionUtil.getVersion((String) object.get(VERSION_KEY));
        final String bukkitVersion = (String) object.get(BUKKIT_VERSION_KEY);
        final String type = (String) object.get(TYPE_KEY);
        final String link = (String) object.get(DOWNLOAD_URL_KEY);
        final FileDescription fileDescription = new FileDescription(fileName, version, link, type,
                bukkitVersion);
        if (VersionUtil.isRelease(version)) {
            result.put(version, fileDescription);
        }
    }
    return result;
}

From source file:net.amigocraft.mpt.command.AddRepositoryCommand.java

@SuppressWarnings("unchecked")
public static String addRepository(String path) throws MPTException {
    if (Thread.currentThread().getId() == Main.mainThreadId)
        throw new MPTException(ERROR_COLOR + "Repositories may not be added from the main thread!");
    try {/*  w ww . j a va  2s .  c om*/
        JSONObject json = MiscUtil.getRemoteIndex(path);
        String id = json.get("id").toString().toLowerCase(); // get ID from remote
        File store = new File(Main.plugin.getDataFolder(), "repositories.json");
        if (!store.exists())
            Main.initializeRepoStore(store); // gotta initialize it before using it
        lockStores();
        JSONObject repoElement = new JSONObject(); // create a new JSON object
        repoElement.put("url", path); // set the repo URL
        ((JSONObject) Main.repoStore.get("repositories")).put(id, repoElement);
        writeRepositoryStore();
        unlockStores();
        return id;
        // apt-get doesn't fetch packages when a repo is added, so I'm following that precedent
    } catch (IOException ex) {
        unlockStores();
        throw new MPTException(ERROR_COLOR + "Failed to add repository to local " + "store!");
    }
}

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

public static Note fromJson(JSONObject obj) {
    Note note = new Note();
    float xPosition = Float.valueOf(obj.get("x").toString());
    float yPosition = Float.valueOf(obj.get("y").toString());
    note.position = new Point2D.Float(xPosition, yPosition);
    note.year = Integer.valueOf(obj.get("year").toString());
    note.month = Integer.valueOf(obj.get("month").toString());
    note.day = Integer.valueOf(obj.get("day").toString());
    note.daysSurvived = Integer.valueOf(obj.get("daysSurvived").toString());
    note.title = obj.get("title").toString();
    note.text = obj.get("text").toString();
    return note;//from w w w .j  ava  2  s . c o  m
}