Example usage for org.json.simple JSONObject put

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

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.tom.deleteme.PrintAnnotations.java

/**
 * Prints all Annotations of a specified Type to a PrintStream.
 * //from  www  .j  a va 2  s.co m
 * @param aCAS
 *          the CAS containing the FeatureStructures to print
 * @param aAnnotType
 *          the Type of Annotation to be printed
 * @param aOut
 *          the PrintStream to which output will be written
 */

public static void printAnnotatedText(FeatureStructure aFS, CAS aCAS, int aNestingLevel, PrintStream aOut,
        JSONObject json) {
    String annotationKey = aFS.getType().getName();
    if (json.get(annotationKey) == null) {
        if (!annotationKey.equals(tcasAnnotationKey)) {
            if (aFS instanceof AnnotationFS) {
                AnnotationFS annot = (AnnotationFS) aFS;
                String coveredText = annot.getCoveredText();
                if (annotationKey.equals(WorkExperienceKey)) {
                    coveredText = stringCleanUp(coveredText, "([\\d]{1,})?.?[\\d]{1,}");
                }
                if (annotationKey.equals(PinCodeKey)) {
                    coveredText = stringCleanUp(coveredText, "[\\d]{6}");
                }
                if (coveredText instanceof String) {
                    coveredText = processString(coveredText);
                }
                if (annotationKey.equals(WorkExperienceKey)) {
                    json.put(aFS.getType().getName(), Float.parseFloat(coveredText));
                } else {
                    json.put(annotationKey, coveredText);
                }
            }
        }
    } else if ((aFS.getType().getName()).equals(OtherNamedTagsKey)) {
        if (aFS instanceof AnnotationFS) {
            AnnotationFS annot = (AnnotationFS) aFS;
            String coveredText = annot.getCoveredText();
            coveredText = processString(coveredText);
            appendOtherNamedTags(json, coveredText);
        }
    }
}

From source file:me.prokopyl.storagemonitor.beans.JavaBean.java

@Override
public String toJSONString() {
    JSONObject obj = new JSONObject();
    obj.put("BeanType", this.getBeanName());
    Field[] fields = this.getClass().getDeclaredFields();

    for (Field field : fields) {
        if (Modifier.isTransient(field.getModifiers()))
            continue;
        field.setAccessible(true);//from  w w  w.j  a v  a2  s. c  om
        try {
            obj.put(field.getName(), field.get(this));
        } catch (IllegalAccessException ex) {
        }
    }

    return obj.toJSONString();
}

From source file:fr.nantes.web.quizz.servlets.Nbdirectors.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    int countdirectors = Requetesdatastore.getcountdirectors();
    JSONArray result = new JSONArray();
    JSONObject map = new JSONObject();
    map.put("count", countdirectors);
    result.add(map);/*w ww  .j ava  2  s . co m*/

    response.setContentType("application/json;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {

        out.println(result);
    }
}

From source file:fr.nantes.web.quizz.servlets.Nbmovies.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    int countmovies = Sparql.countMovies();
    JSONArray result = new JSONArray();
    JSONObject map = new JSONObject();
    map.put("count", countmovies);
    result.add(map);//from  w  w  w .ja va 2  s.  c o  m

    response.setContentType("application/json;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {

        out.println(result);
    }
}

From source file:com.mobicage.rogerthat.form.LocationWidgetResult.java

@SuppressWarnings("unchecked")
@Override/*from w  w w.  ja v a  2 s  . c  o  m*/
public JSONObject toJSONObject() {
    JSONObject obj = new JSONObject();
    obj.put("horizontal_accuracy", this.horizontalAccuracy);
    obj.put("vertical_accuracy", this.verticalAccuracy);
    obj.put("latitude", this.latitude);
    obj.put("longitude", this.longitude);
    obj.put("altitude", this.altitude);
    obj.put("timestamp", this.timestamp);
    return obj;
}

From source file:com.mobicage.rogerthat.form.FloatWidgetResult.java

@SuppressWarnings("unchecked")
@Override/*ww  w.ja  v a 2 s  .c o  m*/
public JSONObject toJSONObject() {
    JSONObject obj = new JSONObject();
    obj.put("value", this.value);
    return obj;
}

From source file:com.opensoc.enrichment.adapters.host.HostFromPropertiesFileAdapter.java

@SuppressWarnings("unchecked")
@Override/*  www .ja va 2 s.c o  m*/
public JSONObject enrich(String metadata) {

    if (!_known_hosts.containsKey(metadata))
        return new JSONObject();

    JSONObject enrichment = new JSONObject();
    enrichment.put("known_info", (JSONObject) _known_hosts.get(metadata));
    return enrichment;
}

From source file:org.kitodo.data.elasticsearch.index.type.UserType.java

@SuppressWarnings("unchecked")
@Override//w  w w  . j  ava2s.c  o m
public HttpEntity createDocument(User user) {

    JSONObject userObject = new JSONObject();
    userObject.put("name", user.getName());
    userObject.put("surname", user.getSurname());
    userObject.put("login", user.getLogin());
    userObject.put("ldapLogin", user.getLdapLogin());
    userObject.put("active", String.valueOf(user.isActive()));
    userObject.put("location", user.getLocation());
    userObject.put("metadataLanguage", user.getMetadataLanguage());
    userObject.put("userGroups", addObjectRelation(user.getUserGroups()));
    userObject.put("filters", addObjectRelation(user.getFilters()));
    userObject.put("projects", addObjectRelation(user.getProjects()));
    userObject.put("processingTasks", addObjectRelation(user.getProcessingTasks()));
    userObject.put("tasks", addObjectRelation(user.getTasks()));

    return new NStringEntity(userObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.actions.AirPressure.java

@SuppressWarnings("unchecked")
@Override/*from w ww. j  a  v  a2  s  .  c  o  m*/
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", ISensorProxy.SENSOR_NAME_AIR_PRESSURE);
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", airPressure);
    }
    return o.toJSONString();
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.actions.Altitude.java

@SuppressWarnings("unchecked")
@Override/*  w  w w  .j  a  v a 2  s.com*/
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", "altitude");
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", altitudeOverGround);
    }
    return o.toJSONString();
}