org.apache.commons.text.StringEscapeUtils.escapeJson()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中org.apache.commons.text.StringEscapeUtils.escapeJson()方法的一些代码示例,展示了StringEscapeUtils.escapeJson()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.escapeJson()方法的具体详情如下:
包路径:org.apache.commons.text.StringEscapeUtils
类名称:StringEscapeUtils
方法名:escapeJson

StringEscapeUtils.escapeJson介绍

暂无

代码示例

代码示例来源:origin: jeremylong/DependencyCheck

/**
 * JSON Encodes the provided text.
 *
 * @param text the text to encode
 * @return the JSON encoded text
 */
public String json(String text) {
  if (text == null || text.isEmpty()) {
    return text;
  }
  return StringEscapeUtils.escapeJson(text);
}

代码示例来源:origin: apache/nifi

private void appendString(final StringBuilder jsonBuilder, final String str, final boolean base64encode) {
  jsonBuilder.append("\"");
  // only escape the value when not doing base64
  if (!base64encode) {
    jsonBuilder.append(StringEscapeUtils.escapeJson(str));
  } else {
    jsonBuilder.append(str);
  }
  jsonBuilder.append("\"");
}

代码示例来源:origin: apache/nifi

private void appendString(final StringBuilder jsonBuilder, final String str, final boolean base64encode) {
  jsonBuilder.append("\"");
  // only escape the value when not doing base64
  if (!base64encode) {
    jsonBuilder.append(StringEscapeUtils.escapeJson(str));
  } else {
    jsonBuilder.append(str);
  }
  jsonBuilder.append("\"");
}

代码示例来源:origin: apache/nifi

protected static String getJsonElement(Object value) {
  if (value instanceof Number) {
    return value.toString();
  } else if (value instanceof Date) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    return "\"" + dateFormat.format((Date) value) + "\"";
  } else if (value instanceof String) {
    return "\"" + StringEscapeUtils.escapeJson((String) value) + "\"";
  } else {
    return "\"" + value.toString() + "\"";
  }
}

代码示例来源:origin: apache/nifi

protected void buildBulkCommand(StringBuilder sb, String index, String docType, String indexOp, String id, String jsonString) {
  if (indexOp.equalsIgnoreCase("index")) {
    sb.append("{\"index\": { \"_index\": \"");
    sb.append(StringEscapeUtils.escapeJson(index));
    sb.append("\", \"_type\": \"");
    sb.append(StringEscapeUtils.escapeJson(docType));
    sb.append("\"");
    if (!StringUtils.isEmpty(id)) {
      sb.append(", \"_id\": \"");
      sb.append(StringEscapeUtils.escapeJson(id));
      sb.append("\"");
  } else if (indexOp.equalsIgnoreCase("upsert") || indexOp.equalsIgnoreCase("update")) {
    sb.append("{\"update\": { \"_index\": \"");
    sb.append(StringEscapeUtils.escapeJson(index));
    sb.append("\", \"_type\": \"");
    sb.append(StringEscapeUtils.escapeJson(docType));
    sb.append("\", \"_id\": \"");
    sb.append(StringEscapeUtils.escapeJson(id));
    sb.append("\" }\n");
    sb.append("{\"doc\": ");
  } else if (indexOp.equalsIgnoreCase("delete")) {
    sb.append("{\"delete\": { \"_index\": \"");
    sb.append(StringEscapeUtils.escapeJson(index));
    sb.append("\", \"_type\": \"");
    sb.append(StringEscapeUtils.escapeJson(docType));
    sb.append("\", \"_id\": \"");
    sb.append(StringEscapeUtils.escapeJson(id));
    sb.append("\" }\n");

代码示例来源:origin: apache/nifi

@Override
public String serialize(byte[] rowKey, ResultCell[] cells) {
  final StringBuilder jsonBuilder = new StringBuilder();
  jsonBuilder.append("{");
  final String row = new String(rowKey, charset);
  jsonBuilder.append("\"row\":")
      .append("\"")
      .append(StringEscapeUtils.escapeJson(row))
      .append("\"");
  jsonBuilder.append(", \"cells\": {");
  int i = 0;
  for (final ResultCell cell : cells) {
    final String cellFamily = new String(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), charset);
    final String cellQualifier = new String(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(), charset);
    if (i > 0) {
      jsonBuilder.append(", ");
    }
    jsonBuilder.append("\"")
        .append(StringEscapeUtils.escapeJson(cellFamily))
        .append(":")
        .append(StringEscapeUtils.escapeJson(cellQualifier))
        .append("\":\"")
        .append(StringEscapeUtils.escapeJson(new String(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(), charset)))
        .append("\"");
    i++;
  }
  jsonBuilder.append("}}");
  return jsonBuilder.toString();
}

代码示例来源:origin: apache/nifi

code = StringEscapeUtils.escapeJson(code);
String payload = "{\"code\":\"" + code + "\"}";
try {

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-api

public AsyncBlob(String key, boolean completed, int progress, String filename) {
  super("{" + "\"key\":\"" + StringEscapeUtils.escapeJson(key) + "\"," + "\"completed\":" + completed + ","
      + "\"progress\":" + progress + "}");
  this.key = key;
  this.completed = completed;
  this.progress = progress;
  setFilename(filename);
}

代码示例来源:origin: org.apache.commons/commons-text

@Test
  public void testDeleteCharacter() {
   final String deleteString = "Delete: \u007F";
   assertEquals("Delete: \\u007F", StringEscapeUtils.escapeJson(deleteString));
  }
}

代码示例来源:origin: com.jwebmp.jre10/jwebmp-core

/**
 * Escapes characters for text appearing as data in the
 *
 * @param input
 *
 * @return
 */
public static String forJSON(String input)
{
  return StringEscapeUtils.escapeJson(input);
}

代码示例来源:origin: com.jwebmp/jwebmp-core

/**
 * Escapes characters for text appearing as data in the
 *
 * @param input
 *
 * @return
 */
public static String forJSON(String input)
{
  return StringEscapeUtils.escapeJson(input);
}

代码示例来源:origin: com.jwebmp.jre11/jwebmp-core

/**
 * Escapes characters for text appearing as data in the
 *
 * @param input
 *
 * @return
 */
public static String forJSON(String input)
{
  return StringEscapeUtils.escapeJson(input);
}

代码示例来源:origin: org.apache.commons/commons-text

@Test
public void testEscapeJson() {
  assertNull(StringEscapeUtils.escapeJson(null));
  try {
    StringEscapeUtils.ESCAPE_JSON.translate(null, null);
    fail("Exception expected!");
  } catch (final IOException ex) {
    fail("Exception expected!");
  } catch (final IllegalArgumentException ex) {
  }
  try {
    StringEscapeUtils.ESCAPE_JSON.translate("", null);
    fail("Exception expected!");
  } catch (final IOException ex) {
    fail("Exception expected!");
  } catch (final IllegalArgumentException ex) {
  }
  assertEquals("He didn't say, \\\"stop!\\\"", StringEscapeUtils.escapeJson("He didn't say, \"stop!\""));
  final String expected = "\\\"foo\\\" isn't \\\"bar\\\". specials: \\b\\r\\n\\f\\t\\\\\\/";
  final String input = "\"foo\" isn't \"bar\". specials: \b\r\n\f\t\\/";
  assertEquals(expected, StringEscapeUtils.escapeJson(input));
}

代码示例来源:origin: org.owasp/dependency-check-core

/**
 * JSON Encodes the provided text.
 *
 * @param text the text to encode
 * @return the JSON encoded text
 */
public String json(String text) {
  if (text == null || text.isEmpty()) {
    return text;
  }
  return StringEscapeUtils.escapeJson(text);
}

代码示例来源:origin: cincheo/jsweet

print(StringEscapeUtils.escapeJson(statement.toString())).print("\"");

代码示例来源:origin: com.heroku.sdk/heroku-deploy

private String getBuildpacksJson() {
 StringBuilder buildpacksString = new StringBuilder();
 for (String url : buildpackUrls) {
  buildpacksString.append(",{\"url\":\"").append(StringEscapeUtils.escapeJson(url)).append("\"}");
 }
 return buildpacksString.toString().replaceFirst(",", "[") + "]";
}

代码示例来源:origin: org.apache.nifi/nifi-cassandra-processors

protected static String getJsonElement(Object value) {
  if (value instanceof Number) {
    return value.toString();
  } else if (value instanceof Date) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    return "\"" + dateFormat.format((Date) value) + "\"";
  } else if (value instanceof String) {
    return "\"" + StringEscapeUtils.escapeJson((String) value) + "\"";
  } else {
    return "\"" + value.toString() + "\"";
  }
}

代码示例来源:origin: heroku/heroku-maven-plugin

private String getBuildpacksJson() {
 StringBuilder buildpacksString = new StringBuilder();
 for (String url : buildpackUrls) {
  buildpacksString.append(",{\"url\":\"").append(StringEscapeUtils.escapeJson(url)).append("\"}");
 }
 return buildpacksString.toString().replaceFirst(",", "[") + "]";
}

代码示例来源:origin: andresth/Kandroid

@NonNull
public static KanboardRequest createComment(int taskid, int userid, @NonNull String comment) {
  return new KanboardRequest("createComment", new String[] {String.format("" +
      "{\n" +
      "    \"jsonrpc\": \"2.0\",\n" +
      "    \"method\": \"createComment\",\n" +
      "    \"id\": 1580417921,\n" +
      "    \"params\": {\n" +
      "        \"task_id\": %d,\n" +
      "        \"user_id\": %d,\n" +
      "        \"content\": \"%s\"\n" +
      "    }\n" +
      "}", taskid, userid, StringEscapeUtils.escapeJson(comment))});
}

代码示例来源:origin: andresth/Kandroid

@NonNull
public static KanboardRequest updateComment(int commentid, @NonNull String comment) {
  return new KanboardRequest("updateComment", new String[] {String.format(
      "{\n" +
      "    \"jsonrpc\": \"2.0\",\n" +
      "    \"method\": \"updateComment\",\n" +
      "    \"id\": 496470023,\n" +
      "    \"params\": {\n" +
      "        \"id\": %d,\n" +
      "        \"content\": \"%s\"\n" +
      "    }\n" +
      "}", commentid, StringEscapeUtils.escapeJson(comment))});
}

相关文章