Example usage for org.json.simple JSONObject toJSONString

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

Introduction

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

Prototype

public String toJSONString() 

Source Link

Usage

From source file:com.aerothai.database.dept.DeptsResource.java

/**
 * Retrieves representation of an instance of com.aerothai.DeptsResource
 * @return an instance of java.lang.String
 *///from  w  ww .  j  a v  a2 s.  c  om
@GET
// Produces JSON as response
@Produces("application/json")
//@Produces("application/xml")
public String listDept() {
    String response = null;

    System.out.println("List Dept All");
    try {
        JSONObject deptData = null;
        DeptService deptService = new DeptService();
        deptData = deptService.GetDeptAll();

        response = deptData.toJSONString();
    } catch (Exception e) {
        System.out.println("error");
    }

    return response;
}

From source file:com.aerothai.database.os.OsResource.java

/**
 * Retrieves representation of an instance of com.aerothai.OsResource
 * @return an instance of java.lang.String
 *//*ww  w .  j a  v a2  s .  c  o  m*/
@GET
@Produces("application/json")
public String listOsAt(@PathParam("id") int id) {
    String response = null;

    System.out.println("List Os At ID");
    try {
        JSONObject osData = null;
        OsService osService = new OsService();
        osData = osService.GetOsAt(id);

        response = osData.toJSONString();
    } catch (Exception e) {
        System.out.println("error");
    }

    return response;
}

From source file:edu.vt.vbi.patric.jbrowse.CRResultSet.java

public CRResultSet(String pin, BufferedReader br) {
    pinGenome = pin.replace("fig|", "").split(".peg.[0-9]*")[0];

    try {//from w  ww.  j  av a 2 s .com
        if (br != null) {
            JSONObject res = (JSONObject) (new JSONParser()).parse(br);

            LOGGER.trace("CompareRegionViewer result: {}", res.toJSONString());

            JSONArray tracks = (JSONArray) res.get(pin);
            genomeNames = new HashSet<>();
            genomeIds = new HashSet<>();
            defaultTracks = new ArrayList<>();
            trackMap = new HashMap<>();

            for (Object track : tracks) {
                JSONObject tr = (JSONObject) track;

                if (((JSONArray) tr.get("features")).size() > 0) {
                    CRTrack crTrk = new CRTrack(tr);
                    trackMap.put(crTrk.getRowID(), crTrk);
                    genomeNames.add(crTrk.getGenomeName());
                    genomeIds.add(crTrk.getGenomeID());
                    if (pinGenome.equals(crTrk.getGenomeID())) {
                        pinStrand = crTrk.findFeature(pin).getStrand();
                    }
                }
            }
        } else {
            LOGGER.error("BufferedReader is null");
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:ch.simas.jtoggl.Tag.java

public Tag(String jsonString) {
    JSONObject object = (JSONObject) JSONValue.parse(jsonString);
    this.id = (Long) object.get("id");
    this.name = (String) object.get("name");

    JSONObject workspaceObject = (JSONObject) object.get("workspace");
    if (workspaceObject != null) {
        this.workspace = new Workspace(workspaceObject.toJSONString());
    }/*from  ww  w . j a v a  2 s.co  m*/
}

From source file:io.personium.client.LinkManager.java

/**
 * This method is used to create a link between two cell control objects.
 * @param cx ILinkageResource/*from  w ww  . java  2 s .com*/
 * @throws DaoException Exception thrown
 */
@SuppressWarnings("unchecked")
public void link(ILinkageResource cx) throws DaoException {
    String uri = getLinkUrl(cx);

    String linksUri = null;
    if (this.accessor.isBatchMode()) {
        linksUri = ((BatchLinksEntity) this.context).getCollectionUrl() + cx.getODataLink();
    } else {
        linksUri = cx.getODataLink();
    }

    JSONObject body = new JSONObject();
    body.put("uri", linksUri);

    IRestAdapter rest = RestAdapterFactory.create(accessor);
    rest.post(uri, body.toJSONString(), RestAdapter.CONTENT_TYPE_JSON);
}

From source file:com.oic.net.WebSocketListener.java

public void sendJson(JSONObject json) {
    try {/*from   w  w  w .j a v a  2s  . co m*/
        session.getRemote().sendString(json.toJSONString());
    } catch (IOException e) {
        LOG.log(Level.WARNING, "send Json error{0}", e);
    }
}

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  w w w  .j a  v a  2  s.  co 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.appzone.sim.services.handlers.AppRegistrationServiceHandlerTest.java

public void testServeConfigureApplication() {

    final HttpServletRequest request = context.mock(HttpServletRequest.class);

    AppRegistrationServiceHandler handler = new AppRegistrationServiceHandler();

    context.checking(new Expectations() {
        {/*from  w  w w  . j  a  v a2 s .  c  om*/
            allowing(request).getParameter(DefaultKewordMatcher.SERVICE_KEYWORD);
            will(returnValue(AppRegistrationServiceHandler.MATCHING_KEYWORD));

            allowing(request).getParameter(AppRegistrationServiceHandler.KEY_INFO_REQUEST);
            will(returnValue(null));

            allowing(request).getParameter(AppRegistrationServiceHandler.KEY_URL);
            will(returnValue("the url"));

            allowing(request).getParameter(AppRegistrationServiceHandler.KEY_USERNAME);
            will(returnValue("the username"));

            allowing(request).getParameter(AppRegistrationServiceHandler.KEY_PASSWORD);
            will(returnValue("the password"));
        }
    });

    Application.configure("http://url", "username", "password");

    Application app = Application.getApplication();
    JSONObject json = new JSONObject();
    json.put(AppRegistrationServiceHandler.JSON_KEY_RESULT, true);

    assertEquals(json.toJSONString(), handler.serve(request));
}

From source file:io.github.casnix.mcdropshop.util.configsys.Shops.java

public static boolean checkShopsFile() {
    File shopsFile = new File("./plugins/mcDropShop/Shops.json");

    if (!shopsFile.exists())
        return false;

    try {/*from w  w  w .  j av  a2  s  .  c  om*/
        String configTable = new String(Files.readAllBytes(Paths.get("./plugins/mcDropShop/Shops.json")));

        JSONParser parser = new JSONParser();

        Object obj = parser.parse(configTable);

        JSONObject jsonObj = (JSONObject) obj;

        String listVersion = (String) jsonObj.get("listVersion");

        if (listVersion == null || !listVersion.equals("0.2.0")) {
            // Old version
            jsonObj.put("listVersion", "0.2.0");

            // Update Shops.json
            FileWriter shopsJSON = new FileWriter("./plugins/mcDropShop/Shops.json");

            shopsJSON.write(jsonObj.toJSONString());

            shopsJSON.flush();
            shopsJSON.close();
        }

        return true;
    } catch (Exception e) {
        Bukkit.getLogger().severe("mcDropShop failed on setup check in Shops.json");

        e.printStackTrace();

        return false;
    }
}

From source file:com.twitter.hdfsdu.TreeSizeByPathServlet.java

@Override
public Iterable<String> getLines(HttpServletRequest request) {
    String paramPath = request.getParameter("path");
    if (paramPath == null) {
        paramPath = "/";
    }//from  www.  j a  v a 2s.c  o  m
    List<String> lines = Lists.newLinkedList();
    List<NodeData> elems = Lists.newArrayList();
    Integer paramDepth = request.getParameter("depth") == null ? 2
            : Integer.parseInt(request.getParameter("depth"));

    try {
        ResultSet resultSet = getSizeByPath(request);
        NodeData data;
        while (resultSet.next()) {
            data = new NodeData();
            data.fileSize = resultSet.getString("size_in_bytes");
            data.nChildren = resultSet.getLong("file_count");
            data.path = resultSet.getString("path");
            data.leaf = resultSet.getBoolean("leaf");
            elems.add(data);
        }
        JSONObject jsonObject = DataTransformer.getJSONTree(paramPath, paramDepth, elems);

        String ans = null;
        if (jsonObject != null) {
            ans = jsonObject.toJSONString();
        }

        if (ans == null) {
            lines.add("{ \"children\": [] }");
        } else {
            lines.add(ans);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return lines;
}