当前位置: 首页>>代码示例>>Java>>正文


Java JSONValue.escape方法代码示例

本文整理汇总了Java中org.json.simple.JSONValue.escape方法的典型用法代码示例。如果您正苦于以下问题:Java JSONValue.escape方法的具体用法?Java JSONValue.escape怎么用?Java JSONValue.escape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.json.simple.JSONValue的用法示例。


在下文中一共展示了JSONValue.escape方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.json.simple.JSONValue; //导入方法依赖的package包/类
@Override
public Object execute(String script) {
    StringBuilder sb = new StringBuilder();
    // Callback for scripts that want to send some message back to page-inspection.
    // We utilize custom alert handling of WebEngine for this purpose.
    sb.append("postMessageToNetBeans=function(e) {alert('"); // NOI18N
    sb.append(WebBrowserImpl.PAGE_INSPECTION_PREFIX);
    sb.append("'+JSON.stringify(e));};\n"); // NOI18N
    String quoted = '\"'+JSONValue.escape(script)+'\"';
    // We don't want to depend on what is the type of WebBrowser.executeJavaScript()
    // for various types of script results => we stringify the result
    // (i.e. pass strings only through executeJavaScript()). We decode
    // the strigified result then.
    sb.append("JSON.stringify({result : eval(").append(quoted).append(")});"); // NOI18N
    String wrappedScript = sb.toString();
    Object result = browserTab.executeJavaScript(wrappedScript);
    String txtResult = result.toString();
    try {
        JSONObject jsonResult = (JSONObject)JSONValue.parseWithException(txtResult);
        return jsonResult.get("result"); // NOI18N
    } catch (ParseException ex) {
        Logger.getLogger(ScriptExecutorImpl.class.getName()).log(Level.INFO, null, ex);
        return ScriptExecutor.ERROR_RESULT;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ScriptExecutorImpl.java

示例2: sendBar

import org.json.simple.JSONValue; //导入方法依赖的package包/类
@Override
public Chat sendBar(String message, Player player) {
    if (!message.startsWith("{") && !message.startsWith("[")) {
        message = "{\"text\":\"" + JSONValue.escape(message) + "\"}";
    }
    PacketPlayOutChat packet = new PacketPlayOutChat(NMSUtil_V1_10_R1.serializeChat(message), (byte)2);
    NMSUtil_V1_10_R1.sendPacket(player, packet);
    return this;
}
 
开发者ID:GameBoxx,项目名称:GameBoxx,代码行数:10,代码来源:Chat_V1_10_R1.java

示例3: getJsonComponent

import org.json.simple.JSONValue; //导入方法依赖的package包/类
private String getJsonComponent(TextAction action, String value, String display) {
    if (action == TextAction.HOVER) {
        //Just a hover text message.
        return getJsonText(display) + ",\"hoverEvent\": {\"action\": \"show_text\",\"value\": {\"text\": \"\",\"extra\": [{" + getJsonText(value) + "}]}}";
    } else {
        //Check for inherited hover message like <<cmd||[[hover||text]]>> it will then display text, on hover display hover and on click run the command cmd.
        Pattern p = Pattern.compile(TextAction.HOVER.getRegex(), Pattern.DOTALL);
        Matcher m = p.matcher(display);

        //When there is hover text change the display text to use the value from hover and set the hover text component.
        String hover = "";
        if (m.find()) {
            hover = ",\"hoverEvent\": {\"action\": \"show_text\",\"value\": {\"text\": \"\",\"extra\": [{" + getJsonText(m.group(2)) + "}]}}";
            display = m.group(3);
        }

        //Insertion doesn't use clickEvent
        if (action == TextAction.INSERT) {
            //We set obfuscated to false to fix the bug where it doesn't work. Bug: [MC-82425]
            return getJsonText(display) + ",\"obfuscated\":false,\"insertion\": \"" + JSONValue.escape(value) + "\"" + hover;
        }

        //Append slash for commands if it's not there.
        if (action == TextAction.CMD || action == TextAction.CMD_SUGGEST && !value.trim().startsWith("/")) {
            value = "/" + value.trim();
        }

        //Return the JSON for general click events.
        return getJsonText(display) + ",\"clickEvent\": {\"action\": \"" + JSONValue.escape(action.getName()) + "\",\"value\": \"" + value + "\"}" + hover;
    }
}
 
开发者ID:GameBoxx,项目名称:GameBoxx,代码行数:32,代码来源:TextParser.java

示例4: getJsonText

import org.json.simple.JSONValue; //导入方法依赖的package包/类
/**
 * Used to get JSON formatted text.
 * <b>This does not parse syntax of {@link TextAction}!</b>
 * <p/>
 * All this does is convert chat colors like §a and §l etc to JSON syntax.
 * For example a string like '§atest §b§lexample' would output in the following JSON:
 * "text":"","extra":[{"text":"test", "color":"green"},{"text":"example","color":"aqua","bold":true}]
 * <p/>
 * <b>Important: </b> As you can see in the example it does not add '{' and '}' before and after the JSON.
 * Manually add this to get valid JSON!
 *
 * @param text The text that needs to be converted to JSON.
 * @return JSON text with tellraw format. (No { in front and no } on the end!)
 */
public static String getJsonText(String text) {
    //When the text doesn't have color codes we just return the text as JSON but without any formatting.
    if (!text.contains("§") || Str.stripColor(text).trim().isEmpty()) {
        return "\"text\":\"" + JSONValue.escape(text) + "\"";
    }

    //Find all color codes within the string.
    //For example '§a' or '§a§l' '§c§l§n' will mitch.
    Pattern p = Pattern.compile("(§[\\da-fA-Fk-oK-OrR])+");
    Matcher m = p.matcher(text);

    StringBuilder JSON = new StringBuilder("\"text\":\"\",\"extra\":[");
    int lastIndex = 0;
    String lastMatch = "";
    while (m.find()) {
        //Create a text section for each set of color codes.
        //Using the #getJsonFormat method to get the formatting for the colors in the current match.
        //We ignore the first match because we want to color the matches with the previous color.
        if (m.start() > lastIndex) {
            JSON.append("{\"text\":\"" + JSONValue.escape(text.substring(lastIndex, m.start())) + "\"" + getJsonFormat(lastMatch) + "}");
            JSON.append(",");
        }
        lastIndex = m.end();
        lastMatch = m.group();
    }

    //Color the last match result if we haven't done it. (Will only be the case when there is one match)
    if (lastIndex < text.length()) {
        JSON.append("{\"text\": \"" + JSONValue.escape(text.substring(lastIndex, text.length())) + "\"" + getJsonFormat(lastMatch) + "}");
    }

    //Remove trailing comma if it's there
    if (JSON.lastIndexOf(",") == JSON.length() - 1) {
        JSON.setLength(JSON.length() - 1);
    }

    //Finalize
    JSON.append("]");
    return JSON.toString();
}
 
开发者ID:GameBoxx,项目名称:GameBoxx,代码行数:55,代码来源:TextParser.java

示例5: escape

import org.json.simple.JSONValue; //导入方法依赖的package包/类
/**
 * Escapes the string to fit into Json values. Used internally.
 * @param text text to escape
 * @return escaped String
 */
public static String escape(String text) {
    return JSONValue.escape(text);
}
 
开发者ID:NamelessMC,项目名称:Nameless-Plugin,代码行数:9,代码来源:Json.java


注:本文中的org.json.simple.JSONValue.escape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。