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

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

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

StringEscapeUtils.unescapeJson介绍

[英]Unescapes any Json literals found in the String.

For example, it will turn a sequence of '' and 'n'into a newline character, unless the '' is preceded by another ''.
[中]取消扫描字符串中找到的任何Json文本。
例如,它会将“\”和“n”的序列转换为换行符,除非“\”前面有另一个“\”。

代码示例

代码示例来源:origin: Swagger2Markup/swagger2markup

example = stripExampleQuotes(StringEscapeUtils.unescapeJson(example));
if (entryByType.getKey().equals("application/json")) {
  String example = Json.pretty(entryByType.getValue());
  example = stripExampleQuotes(StringEscapeUtils.unescapeJson(example));

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

@Test
  public void testUnescapeJson() {
    assertNull(StringEscapeUtils.unescapeJson(null));
    try {
      StringEscapeUtils.UNESCAPE_JSON.translate(null, null);
      fail();
    } catch (final IOException ex) {
      fail();
    } catch (final IllegalArgumentException ex) {
    }
    try {
      StringEscapeUtils.UNESCAPE_JSON.translate("", null);
      fail();
    } catch (final IOException ex) {
      fail();
    } catch (final IllegalArgumentException ex) {
    }

    assertEquals("He didn't say, \"stop!\"", StringEscapeUtils.unescapeJson("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.unescapeJson(input));
  }
}

代码示例来源:origin: neuland/jade4j

throw new JadeLexerException(e.getMessage(), filename, lineno, templateLoader);
val = StringEscapeUtils.unescapeJson(val);
key = key.trim();
key = key.replaceAll("^['\"]|['\"]$", "");

代码示例来源:origin: priiduneemre/btcd-cli4j

public String unescapeJson(String json) {
    return StringEscapeUtils.unescapeJson(json);
  }
}

代码示例来源:origin: org.eclipse.dirigible/dirigible-api-utils

/**
 * Unescape JSON.
 *
 * @param input
 *            the input
 * @return the unescaped input
 */
public static final String unescapeJson(String input) {
  return StringEscapeUtils.unescapeJson(input);
}

代码示例来源:origin: org.eclipse.dirigible/dirigible-api-facade-utils

/**
 * Unescape JSON.
 *
 * @param input
 *            the input
 * @return the unescaped input
 */
public static final String unescapeJson(String input) {
  return StringEscapeUtils.unescapeJson(input);
}

代码示例来源:origin: com.linkedin.pegasus/data

/**
 * Unescapes a PDL string literal.
 *
 * @param stringLiteral provides an escaped PDL string literal.
 * @return a string literal.
 */
public static String extractString(String stringLiteral)
{
 return StringEscapeUtils.unescapeJson(stringLiteral.substring(1, stringLiteral.length() - 1));
}

代码示例来源:origin: org.coursera.courier/courier-grammar

public static String extractString(String stringLiteral) {
 return StringEscapeUtils
  .unescapeJson(stringLiteral.substring(1, stringLiteral.length() - 1));
}

代码示例来源:origin: org.onap.dcaegen2.analytics.tca/dcae-analytics-dmaap

/**
 * Adds unescaped Json messages to given messages list
 *
 * @param messages message list in which unescaped messages will be added
 * @param incomingMessageString incoming message string that may need to be escaped
 */
private static void addUnescapedJsonToMessage(List<String> messages, String incomingMessageString) {
  if (incomingMessageString.startsWith("\"") && incomingMessageString.endsWith("\"")) {
    messages.add(StringEscapeUtils.unescapeJson(
        incomingMessageString.substring(1, incomingMessageString.length() - 1)));
  } else {
    messages.add(StringEscapeUtils.unescapeJson(incomingMessageString));
  }
}

代码示例来源:origin: com.github.hackerwin7/jlib-utils

private static void getConf2(String jobId) throws Exception {
  String enc = "UTF-8";
  String appid = "bdp.jd.com";
  appid = URLEncoder.encode(appid, enc);
  String token = "RQLMPXULF3EG23CPZL3U257B7Y";
  token = URLEncoder.encode(token, enc);
  String addr = "http://test.atom.bdp.jd.com/api/site/getOrigin";
  String time = String.valueOf(System.currentTimeMillis());
  //data
  String data = "{\"key\":\"" + jobId + "\",\"erp\":\"fanwenqi\"," + "\"model\":\"rpc\"}";
  data = URLEncoder.encode(data, enc);
  //post url
  String url = addr + "?appId=" + appid + "&token=" + token + "&time=" + time + "&data=" + data;
  HttpGet request = new HttpGet(url);
  HttpResponse response = httpClient.execute(request);
  String ret = EntityUtils.toString(response.getEntity(), enc);
  System.out.println(ret);
  //show config
  JSONObject jret = new JSONObject(ret);
  String origin = jret.getString("obj");
  String value = StringEscapeUtils.unescapeJson(origin);
  System.out.println(new JSONObject(value));
}
private static void getConf3(String jobId) throws Exception {

代码示例来源:origin: com.github.hackerwin7/jlib-utils

String objStr = new JSONObject(ret).getString("obj");
System.out.println(objStr);
String objOrigin = StringEscapeUtils.unescapeJson(objStr);
JSONObject jobj = new JSONObject(objOrigin);
System.out.println(jobj.toString());

代码示例来源:origin: PortSwigger/backslash-powered-scanner

static byte[] filterResponse(byte[] response) {
  if (response == null) {
    return new byte[]{'n','u','l','l'};
  }
  byte[] filteredResponse;
  IResponseInfo details = helpers.analyzeResponse(response);
  String inferredMimeType = details.getInferredMimeType();
  if(inferredMimeType.isEmpty()) {
    inferredMimeType = details.getStatedMimeType();
  }
  inferredMimeType = inferredMimeType.toLowerCase();
  if(inferredMimeType.contains("text") || inferredMimeType.equals("html") || inferredMimeType.contains("xml") || inferredMimeType.contains("script") || inferredMimeType.contains("css") || inferredMimeType.contains("json")) {
    filteredResponse = helpers.stringToBytes(helpers.bytesToString(response).toLowerCase());
  }
  else {
    String headers = helpers.bytesToString(Arrays.copyOfRange(response, 0, details.getBodyOffset())) + details.getInferredMimeType();
    filteredResponse = helpers.stringToBytes(headers.toLowerCase());
  }
  if(details.getStatedMimeType().toLowerCase().contains("json") && (inferredMimeType.contains("json") || inferredMimeType.contains("javascript"))) {
    String headers = helpers.bytesToString(Arrays.copyOfRange(response, 0, details.getBodyOffset()));
    String body =  helpers.bytesToString(Arrays.copyOfRange(response, details.getBodyOffset(), response.length));
    filteredResponse = helpers.stringToBytes(headers + StringEscapeUtils.unescapeJson(body));
  }
  return filteredResponse;
}

代码示例来源:origin: PortSwigger/param-miner

static byte[] filterResponse(byte[] response) {
  if (response == null) {
    return new byte[]{'n','u','l','l'};
  }
  byte[] filteredResponse;
  IResponseInfo details = helpers.analyzeResponse(response);
  String inferredMimeType = details.getInferredMimeType();
  if(inferredMimeType.isEmpty()) {
    inferredMimeType = details.getStatedMimeType();
  }
  inferredMimeType = inferredMimeType.toLowerCase();
  if(inferredMimeType.contains("text") || inferredMimeType.equals("html") || inferredMimeType.contains("xml") || inferredMimeType.contains("script") || inferredMimeType.contains("css") || inferredMimeType.contains("json")) {
    filteredResponse = helpers.stringToBytes(helpers.bytesToString(response).toLowerCase());
  }
  else {
    String headers = helpers.bytesToString(Arrays.copyOfRange(response, 0, details.getBodyOffset())) + details.getInferredMimeType();
    filteredResponse = helpers.stringToBytes(headers.toLowerCase());
  }
  if(details.getStatedMimeType().toLowerCase().contains("json") && (inferredMimeType.contains("json") || inferredMimeType.contains("javascript"))) {
    String headers = helpers.bytesToString(Arrays.copyOfRange(response, 0, details.getBodyOffset()));
    String body =  helpers.bytesToString(Arrays.copyOfRange(response, details.getBodyOffset(), response.length));
    filteredResponse = helpers.stringToBytes(headers + StringEscapeUtils.unescapeJson(body));
  }
  return filteredResponse;
}

代码示例来源:origin: io.github.swagger2markup/swagger2markup

example = stripExampleQuotes(StringEscapeUtils.unescapeJson(example));

代码示例来源:origin: org.tomitribe/swagger2markup

example = stripExampleQuotes(StringEscapeUtils.unescapeJson(example));

代码示例来源:origin: de.neuland-bfi/jade4j

throw new JadeLexerException(e.getMessage(), filename, lineno, templateLoader);
val = StringEscapeUtils.unescapeJson(val);
key = key.trim();
key = key.replaceAll("^['\"]|['\"]$", "");

代码示例来源:origin: discord-java/discord.jar

user = (user == null) ? api.getBlankUser() : user;
String msgContent = StringEscapeUtils.unescapeJson(content.getString("content"));
String msgId = content.getString("id");

相关文章