Example usage for org.json.simple JSONObject escape

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

Introduction

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

Prototype

public static String escape(String s) 

Source Link

Usage

From source file:lv.semti.Thesaurus.utils.JSONUtils.java

public static <E> String simplesToJSON(Iterable<E> l) {
    if (l == null)
        return "[]";
    StringBuilder res = new StringBuilder();
    res.append("[");
    Iterator<E> i = l.iterator();
    while (i.hasNext()) {
        res.append("\"");
        res.append(JSONObject.escape(i.next().toString()));
        res.append("\"");
        if (i.hasNext())
            res.append(", ");
    }/*from   w w  w .j av  a 2s.  c om*/
    res.append("]");
    return res.toString();
}

From source file:lv.semti.Thesaurus.struct.Gloss.java

public String toJSON() {
    return String.format("\"Gloss\":\"%s\"", JSONObject.escape(text));
}

From source file:com.twosigma.beaker.core.rest.PublishRest.java

@POST
@Path("github")
@Produces(MediaType.APPLICATION_JSON)//from   w w w .  jav a  2s .  com
public String notebook(@FormParam("json") String json, @FormParam("type") String type)
        throws IOException, ClientProtocolException {
    String files = "{\"Beaker Share\":{\"content\":\"" + JSONObject.escape(json) + "\"}}";
    String body = "{\"description\":\"Beaker Share\",\"public\":true,\"files\":" + files + "}\n";
    String response = null;
    try {
        response = Request.Post(this.gistUrl).useExpectContinue().version(HttpVersion.HTTP_1_1)
                .bodyString(body, ContentType.APPLICATION_JSON).execute().returnContent().asString();
    } catch (Throwable t) {
        throw new GistPublishException(ExceptionUtils.getStackTrace(t));
    }
    JSONObject parsed = (JSONObject) JSONValue.parse(response);
    String githubUrl = (String) parsed.get("html_url");
    int slash = githubUrl.lastIndexOf("/");
    if (slash < 0) {
        System.err.println("no slash found in github url: " + githubUrl);
        return githubUrl;
    }
    return this.sharingUrl + githubUrl.substring(slash);
}

From source file:gov.nasa.jpl.celgene.labkey.LabkeyDumper.java

public void generateJSON(List<Map<String, Object>> studyData) {

    // loop over the returned rows
    System.out.println("{\"studies\":[");
    for (int i = 0; i < studyData.size(); i++) {
        Map<String, Object> study = studyData.get(i);
        System.out.println("{");
        String[] keySet = study.keySet().toArray(new String[] {});
        for (int j = 0; j < keySet.length; j++) {
            String key = keySet[j];
            if (j + 1 >= keySet.length) {
                System.out.println(
                        "\"" + key + "\" : \"" + JSONObject.escape(String.valueOf(study.get(key))) + "\"");
            } else {
                System.out.println(
                        "\"" + key + "\" : \"" + JSONObject.escape(String.valueOf(study.get(key))) + "\",");
            }//from  ww  w .ja  v a 2 s.co m
        }
        if (i + 1 >= studyData.size()) {
            System.out.println("}");
        } else {
            System.out.println("},");
        }
    }
    System.out.println("]}");
}

From source file:lv.semti.Thesaurus.struct.Lemma.java

public String toJSON() {
    StringBuilder res = new StringBuilder();
    res.append(String.format("\"Lemma\":\"%s\"", JSONObject.escape(text)));
    if (pronunciation != null) {
        res.append(", \"Pronunciation\":\"");
        res.append(JSONObject.escape(pronunciation.toString()));
        res.append("\"");
    }//  w w  w .j a  va  2s.c  o  m
    return res.toString();
}

From source file:lv.semti.Thesaurus.struct.Phrase.java

public String toJSON() {
    StringBuilder res = new StringBuilder();

    res.append("\"Phrase\":{");
    boolean hasPrev = false;

    if (text != null) {
        if (hasPrev)
            res.append(", ");
        res.append("\"Text\":\"");
        res.append(JSONObject.escape(text));
        res.append("\"");
        hasPrev = true;/*w  ww  .  j a  v a2 s. c o m*/
    }

    if (grammar != null) {
        if (hasPrev)
            res.append(", ");
        res.append(grammar.toJSON());
        hasPrev = true;
    }

    if (subsenses != null) {
        if (hasPrev)
            res.append(", ");
        res.append("\"Senses\":");
        res.append(JSONUtils.objectsToJSON(subsenses));
        hasPrev = true;
    }

    res.append("}");
    return res.toString();
}

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

@Override
void write(Writer out) throws IOException {
    //this.raw().writeJSONString(out);
    if (raw == null) {
        out.write("null");
    } else {/*from ww w  .  j  av a  2  s.c  o m*/
        boolean first = true;
        Iterable<String> keys = keys();
        Iterator<String> iter = keys.iterator();

        out.write('{');
        while (iter.hasNext()) {
            if (first) {
                first = false;
            } else {
                out.write(',');
            }
            String key = iter.next();
            Object value = raw.get(key);

            out.write('\"');
            out.write(JSONObject.escape(key));
            out.write('\"');
            out.write(':');
            JSONWrapper.write(value, out);
        }
        out.write('}');
    }
    out.flush();
}

From source file:lv.semti.Thesaurus.struct.Sense.java

public String toJSON() {
    StringBuilder res = new StringBuilder();

    boolean hasPrev = false;

    if (ordNumber != null) {
        res.append("\"SenseID\":\"");
        res.append(JSONObject.escape(ordNumber.toString()));
        res.append("\"");
        hasPrev = true;//from   w w  w  . j  ava  2  s  .  c  om
    }

    if (grammar != null) {
        if (hasPrev)
            res.append(", ");
        res.append(grammar.toJSON());
        hasPrev = true;
    }

    if (gloss != null) {
        if (hasPrev)
            res.append(", ");
        res.append(gloss.toJSON());
        hasPrev = true;
    }

    if (examples != null && !examples.isEmpty()) {
        if (hasPrev)
            res.append(", ");
        res.append("\"Examples\":");
        res.append(JSONUtils.objectsToJSON(examples));
        hasPrev = true;
    }

    if (subsenses != null && !subsenses.isEmpty()) {
        if (hasPrev)
            res.append(", ");
        res.append("\"Senses\":");
        res.append(JSONUtils.objectsToJSON(subsenses));
        hasPrev = true;
    }

    return res.toString();
}

From source file:lv.semti.Thesaurus.struct.ThesaurusEntry.java

/**
 * Build a JSON representation, designed to load in Tezaurs2 webapp well.
 * @return JSON representation//from www  .  j av a 2  s .  c  om
 */
public String toJSON() {
    StringBuilder s = new StringBuilder();
    s.append('{');
    s.append(head.toJSON());
    /*if (paradigm != 0) {
       s.append(String.format(",\"Paradigm\":%d", paradigm));
       if (analyzer != null) {
    // generate a list of inflected wordforms and format them as JSON array
    ArrayList<Wordform> inflections = analyzer.generateInflections(lemma.l, paradigm);
    s.append(String.format(",\"Inflections\":%s", formatInflections(inflections) )); 
       }
    }//*/

    if (homId != null) {
        s.append(", \"ID\":\"");
        s.append(JSONObject.escape(homId.toString()));
        s.append("\"");
    }

    s.append(", \"Senses\":");
    s.append(JSONUtils.objectsToJSON(senses));

    if (phrases != null) {
        s.append(", \"Phrases\":");
        s.append(JSONUtils.objectsToJSON(phrases));
    }

    if (derivs != null) {
        s.append(", \"Derivatives\":");
        s.append(JSONUtils.objectsToJSON(derivs));
    }

    if (sources != null && !sources.isEmpty()) {
        s.append(",");
        s.append(sources.toJSON());
    }
    s.append('}');
    return s.toString();
}

From source file:de.Keyle.MyPet.compat.v1_8_R1.PlatformHelper.java

public void sendMessageActionBar(Player player, String message) {
    if (player instanceof CraftPlayer) {
        IChatBaseComponent cbc = ChatSerializer.a("{\"text\": \"" + JSONObject.escape(message) + "\"}");
        ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(cbc, (byte) 2));
    }/*from   w  w  w .  ja  va2  s  .c om*/
}