Example usage for org.json.simple JSONObject JSONObject

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

Introduction

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

Prototype

JSONObject

Source Link

Usage

From source file:com.oic.event.PosUpdate.java

@Override
public void ActionEvent(JSONObject json, WebSocketListener webSocket) {
    JSONObject responseJSON = new JSONObject();
    responseJSON.put("method", "posupdate");
    responseJSON.put("status", 0);
    if (validate(json)) {
        MapFactory mapFactory = MapFactory.getInstance();
        OicMap map = mapFactory.getMap(Integer.parseInt(json.get("mapid").toString()));
        map.BroadCastMap(responseJSON);/*w w w .  ja  va  2 s  .com*/
    } else {
        OicCharacter c = webSocket.getCharacter();
        c.getMap().BroadCastMap(responseJSON);
    }
}

From source file:com.oic.event.map.TransferMap.java

@Override
public void ActionEvent(JSONObject json, WebSocketListener webSocket) {
    JSONObject responseJSON = new JSONObject();
    responseJSON.put("method", "transfermap");
    if (!validation(json)) {
        responseJSON.put("status", "1");
        webSocket.sendJson(responseJSON);
        return;//w  w  w  .  jav  a 2s  .  c  om
    }
    int oldMapid = webSocket.getCharacter().getMapid();
    int mapid = Integer.parseInt(json.get("mapid").toString());
    OicCharacter c = webSocket.getCharacter();
    c.changeMap(mapid);
    responseJSON.put("mapid", mapid);
    responseJSON.put("status", 0);
    webSocket.sendJson(responseJSON);

    //
    new PosUpdate().ActionEvent(responseJSON, webSocket); //??

    responseJSON.put("mapid", oldMapid);
    new PosUpdate().ActionEvent(responseJSON, webSocket); //??        
}

From source file:JavaCloud.Cloud.java

public static Cloud register(String address, String login, String password, String name, String surname,
        String email) throws CoreException {
    JSONObject object = new JSONObject();
    object.put("login", login);
    object.put("password", password);
    object.put("name", name);
    object.put("surname", surname);
    object.put("email", email);
    Utils.request(address, "/user/user/register/", object);
    return new Cloud(address, login, password);
}

From source file:com.oic.event.map.GetMapList.java

@Override
public void ActionEvent(JSONObject json, WebSocketListener webSocket) {
    JSONObject responseJSON = new JSONObject();
    responseJSON.put("method", "getmaplist");
    MapFactory mapFactory = MapFactory.getInstance();
    Map<Integer, String> maps = new HashMap<>();
    for (OicMap map : mapFactory.getMapList()) {
        maps.put(map.getMapId(), map.getMapName());
    }/*w w w .  j  av  a 2s.  c o m*/
    responseJSON.put("maplist", maps);
    webSocket.sendJson(responseJSON);
}

From source file:mysynopsis.JSONWriter.java

public static void writeData() throws IOException {

    JSONObject bio = new JSONObject();
    bio.put("Name", name);
    bio.put("Initial", initial);
    bio.put("Bio", biog);
    bio.put("Designation", designation);
    bio.put("Department", dept);
    bio.put("University", university);
    bio.put("University_Address", universityAddress);
    bio.put("Office", office);
    bio.put("Ohours", officehours);
    bio.put("Phone", phone);
    bio.put("Email", email);
    bio.put("Resume_Link", resumelink);
    bio.put("Educational", education);
    bio.put("Professional", professional);

    bio.put("Awards", awards);

    bio.put("Image_Ext", imgExtension);
    bio.put("Image_String", imgString);

    /*JSONArray education = new JSONArray();
    for(int i=0;i<8;i++) {//from  ww  w.jav a2  s .c o  m
    education.add(educ[i]);
    }
    bio.put("Education",education);*/

    JSONArray ftpinfo = new JSONArray();

    ftpinfo.add(server);
    ftpinfo.add(user);
    ftpinfo.add(dir);

    bio.put("Server_Information", ftpinfo);

    try (FileWriter file = new FileWriter("data.json")) {

        file.write(bio.toJSONString());
    } catch (IOException e) {

        JOptionPane.showMessageDialog(null,
                "Can't Create Data.json File. Please Check Your Directory Permission");
    }
}

From source file:com.oic.event.map.GetMapInfo.java

@Override
public void ActionEvent(JSONObject json, WebSocketListener webSocket) {
    JSONObject responseJSON = new JSONObject();
    responseJSON.put("method", "getmapinfo");
    if (!validation(json)) {
        responseJSON.put("status", "1");
        webSocket.sendJson(responseJSON);
        return;//from  w  w w .  ja  v  a 2 s  .c  om
    }

    MapFactory factory = MapFactory.getInstance();
    int mapid = Integer.parseInt(json.get("mapid").toString());
    OicMap map = factory.getMap(mapid);

    responseJSON.put("mapid", map.getMapId());
    responseJSON.put("imgpath", map.getPath());
    JSONObject posJSON = new JSONObject();
    Position pos = map.getPos();
    posJSON.put("x", pos.getX());
    posJSON.put("y", pos.getX());
    posJSON.put("width", pos.getWidth());
    posJSON.put("height", pos.getHeight());
    responseJSON.put("pos", posJSON);
    webSocket.sendJson(responseJSON);
}

From source file:com.boundlessgeo.geoserver.json.JSONObj.java

public JSONObj() {
    this(new JSONObject());
    order = new ArrayList<String>();
}

From source file:JSON.WriteQuestionnaireJSON.java

public void buildJSON(String quesString, String quesid) {
    JSONObject ques = new JSONObject();
    ques.put("name", quesid);
    ques.put("question", quesString);
    JSONArray options = new JSONArray();
    options.add("High");
    options.add("Medium");
    options.add("Low");
    ques.put("options", options);

    questions.add(ques);/*from  ww w .  j  a va2  s. c  om*/
}

From source file:at.ac.tuwien.dsg.quelle.sesConfigurationsRecommendationService.util.ConvertTOJSON.java

public static String convertTOJSON(MultiLevelRequirements levelRequirements) {
    if (levelRequirements == null) {
        return "{nothing}";
    }//from   w w w  . ja va  2 s  .  c o m
    JSONObject root = new JSONObject();
    //diff is that in some cases (e.g. condition), name is displayName
    root.put("name", levelRequirements.getName());
    root.put("realName", levelRequirements.getName());
    root.put("type", "" + levelRequirements.getLevel());

    //traverse recursive XML tree
    List<JSONObject> jsonObjects = new ArrayList<>();
    List<MultiLevelRequirements> reqsList = new ArrayList<>();

    reqsList.add(levelRequirements);
    jsonObjects.add(root);

    while (!reqsList.isEmpty()) {
        JSONObject obj = jsonObjects.remove(0);
        MultiLevelRequirements reqs = reqsList.remove(0);

        JSONArray children = new JSONArray();
        for (MultiLevelRequirements childReqs : reqs.getContainedElements()) {
            JSONObject child = new JSONObject();
            child.put("name", childReqs.getName());
            child.put("realName", childReqs.getName());
            child.put("type", "" + childReqs.getLevel());
            children.add(child);

            reqsList.add(childReqs);
            jsonObjects.add(child);
        }

        //add strategies
        for (Strategy strategy : reqs.getOptimizationStrategies()) {
            JSONObject strategyJSON = new JSONObject();
            strategyJSON.put("name", "" + strategy.getStrategyCategory().toString());
            strategyJSON.put("realName", "" + strategy.getStrategyCategory().toString());
            strategyJSON.put("type", "Strategy");
            children.add(strategyJSON);
        }

        //            JSONArray unitReqs = new JSONArray();
        for (Requirements requirements : reqs.getUnitRequirements()) {
            JSONObject child = new JSONObject();
            child.put("name", requirements.getName());
            child.put("realName", requirements.getName());
            child.put("type", "RequirementsBlock");
            children.add(child);

            JSONArray requirementsJSON = new JSONArray();

            for (Requirement requirement : requirements.getRequirements()) {
                JSONObject requirementJSON = new JSONObject();
                requirementJSON.put("name", requirement.getName());
                requirementJSON.put("realName", requirement.getName());
                requirementJSON.put("type", "Requirement");
                //put individual conditions
                JSONArray conditions = new JSONArray();

                for (Condition condition : requirement.getConditions()) {
                    JSONObject conditionJSON = new JSONObject();
                    conditionJSON.put("name", "MUST BE " + condition.toString());
                    conditionJSON.put("type", "Condition");
                    conditionJSON.put("realName", "" + condition.getType());
                    conditions.add(conditionJSON);
                }

                requirementJSON.put("children", conditions);
                requirementsJSON.add(requirementJSON);
            }

            child.put("children", requirementsJSON);

        }

        obj.put("children", children);

    }

    return root.toJSONString();
}

From source file:com.iitb.cse.Utils.java

@SuppressWarnings("unchecked")

static String getApSettingsFileJson(String message) {
    JSONObject obj = new JSONObject();
    obj.put(Constants.action, Constants.sendApSettings);
    String[] apConf = message.split("\n");
    System.out.println(apConf.length);

    for (int i = 0; i < apConf.length; i++) {
        String[] apInfo = apConf[i].trim().split("=");
        if (apInfo[0].equalsIgnoreCase("USERNAME")) {

            if (apInfo.length == 1) {

                obj.put(Constants.username, "");
            } else {
                String _usrname = apInfo[1].trim();
                obj.put(Constants.username, _usrname);
            }//www . j  a v  a2s.  c  om

        } else if (apInfo[0].equalsIgnoreCase("PASSWORD")) {

            if (apInfo.length == 1) {
                //String _usrname = apInfo[1].trim();
                obj.put(Constants.password, "");
            } else {
                String _passwd = apInfo[1].trim();
                obj.put(Constants.password, _passwd);
            }

        } else if (apInfo[0].equalsIgnoreCase("BSSID")) {

            if (apInfo.length == 1) {
                obj.put(Constants.bssid, "");
            } else {
                String _bssid = apInfo[1].trim();
                obj.put(Constants.bssid, _bssid);
            }

        } else if (apInfo[0].equalsIgnoreCase("SSID")) {

            if (apInfo.length == 1) {
                obj.put(Constants.ssid, "");
            } else {
                String _ssid = apInfo[1].trim();
                obj.put(Constants.ssid, _ssid);
            }

        } else if (apInfo[0].equalsIgnoreCase("SECURITY")) {

            if (apInfo.length == 1) {
                obj.put("security", "");
            } else {
                String _sec = apInfo[1].trim();
                obj.put("security", _sec);
            }

        }
    }

    //obj.put(Constants.message,message);
    //   obj.put(Constants.textFileFollow, Boolean.toString(true));
    //   obj.put(Constants.serverTime, Long.toString(Calendar.getInstance().getTimeInMillis()));
    String jsonString = obj.toJSONString();
    System.out.println(jsonString);
    return jsonString;
}