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.mum.edu.cs472.dictServlet.java

public static JSONArray convertToJSON(ResultSet resultSet) throws Exception {
    JSONArray jsonArray = new JSONArray();
    while (resultSet.next()) {
        int total_rows = resultSet.getMetaData().getColumnCount();
        JSONObject obj = new JSONObject();
        for (int i = 0; i < total_rows; i++) {
            obj.put(resultSet.getMetaData().getColumnLabel(i + 1).toLowerCase(), resultSet.getObject(i + 1));
            jsonArray.add(obj);// w  ww . ja v a 2  s. c o m
        }
    }
    return jsonArray;
}

From source file:Json.Type.java

public Type(String type) {
    JSONObject obj = new JSONObject();
    obj.put("type", type);
    File file = new File("type");

    try {//  w w  w.  ja  va 2s .c o  m
        //?,  ?   ??  ? 
        if (!file.exists()) {
            file.createNewFile();
        }

        //PrintWriter ? ? ?  
        PrintWriter out = new PrintWriter(file.getAbsoluteFile());

        try {
            //? ?  
            out.print(obj);
        } finally {
            //?     
            //   ??
            out.close();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

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

public static String fromListToJSONString(String key, List<String> list) {

    JSONObject json = new JSONObject();

    JSONArray array = new JSONArray();
    array.addAll(list);//from  w  w w.  j  av a  2  s.c  o m

    json.put(key, array);

    return json.toString();
}

From source file:co.edu.unal.arqdsoft.presentacion.JSON.java

/**
 * //from  w w  w. ja  v a  2 s. c o m
 * @param arg
 * @return JSON String del ojbeto parametro
 */
public static String toString(Respuesta arg) {
    JSONObject obj = new JSONObject();
    obj.put("error", arg.getError());
    obj.put("contenido", arg.getContenido().toJSON());
    return obj.toJSONString();
}

From source file:ch.newscron.shortUrlUtils.ShortenerURL.java

/**
 * Given a long original URL, the function makes a request to the Google API (with key) and takes out the shortened goo.gl URL from the received JsonNode. 
 * @param longURL is the full (domain/path/ENCODED_DATA) URL created for inviting potential members
 * @return a String which is the goo.gl shortened URL correlated to the original long URL.
 *///  w ww.  j a v  a 2s . c  om
public static String getShortURL(String longURL) {
    try {
        JSONObject data = new JSONObject();
        data.put("longUrl", longURL);

        // HTTP request with the result
        HttpResponse<com.mashape.unirest.http.JsonNode> postResponse = Unirest.post(google_url)
                .header("Content-Type", "application/json").body(data.toJSONString()).asJson();
        return (String) postResponse.getBody().getObject().get("id"); //If everything is working, then return the shortened URL

    } catch (Exception e) {
    }

    return null; //In case of errors or problems, just return the full and long URL
}

From source file:com.dubture.symfony.core.util.JsonUtils.java

@SuppressWarnings("unchecked")
public static String createReference(String elementName, String qualifier, String viewPath, String method) {

    JSONObject data = new JSONObject();
    data.put("elementName", elementName);
    data.put("qualifier", qualifier);
    data.put("viewPath", viewPath);
    data.put("method", method);

    JSONObject header = new JSONObject();
    header.put("type", "reference");
    header.put("data", data);

    return header.toString();

}

From source file:JSON.WriteProductJSON.java

public WriteProductJSON() {
    products = new JSONObject();
    details = new JSONArray();
}

From source file:JSON.WriteQuestionnaireJSON.java

public WriteQuestionnaireJSON() {
    questionnaire = new JSONObject();
    questions = new JSONArray();
}

From source file:gov.nih.nci.caintegrator.application.lists.ajax.CommonListFunctions.java

public static String getListAsList(ListType ty) {

    JSONObject res = new JSONObject();
    res.put("listType", ty.toString());

    String results = "";

    HttpSession session = ExecutionContext.get().getSession(false);
    UserListBeanHelper helper = new UserListBeanHelper(session);

    List patientLists = helper.getLists(ty);
    if (!patientLists.isEmpty()) {
        for (int i = 0; i < patientLists.size(); i++) {
            UserList list = (UserList) patientLists.get(i);
            ListManager uploadManager = (ListManager) ListManager.getInstance();
            Map paramMap = uploadManager.getParams(list);
            String commas = StringUtils.join(list.getList().toArray(), ",");
            String sty = list.getListOrigin() != null && !list.getListOrigin().equals(ListOrigin.Default)
                    ? "color:#A90101"
                    : "color:#000";
            results += ("<li id='" + paramMap.get("listName") + "' title='" + commas + "' style='" + sty + "'>"
                    + paramMap.get("listName") + "</li>");
        }//w  ww  .ja  v a  2 s  . com
    } else {
        results = "";
    }
    res.put("LIs", results);
    return res.toString();
}

From source file:msuresh.raftdistdb.RaftCluster.java

public static void createDefaultGlobal() throws IOException {
    JSONObject obj = new JSONObject();
    obj.put("currentCount", 5000);
    try (FileWriter file = new FileWriter(Constants.STATE_LOCATION + "global.info")) {
        file.write(obj.toJSONString());//from ww w  .j a va2s. c  o m
    }
}