gpt4 book ai didi

java - 如何在JAVA中转义特殊字符Restful API查询字符串

转载 作者:行者123 更新时间:2023-12-04 08:21:29 26 4
gpt4 key购买 nike

我尝试修改现有的查询字符串以过滤指定的条件:
现在查询字符串如下:

String bodycontent="{"
+" \"_source\": [\"@timestamp\",\"eqpid\",\"lotid\",\"stageid\",\"srvmethod\",\"parm_1\",\"apcack\",\"description\",\"host\",\"path\",\"action\"],"
+" \"query\": {"
+" \"query_string\" : {"
+" \"query\":\" lotid:"+q_lotid+" AND "+host_type+"\"}"
+" },"
+" \"sort\" : [{\"@timestamp\" : { \"order\" : \"desc\" }}]"
+"}";
我想更改以下查询条件:
query :
type:ams_log AND (alm_source:K*) AND (alm_id:TCS00004 OR alm_id:TCS00005 OR alm_id:TCS00007 OR alm_id:TCS00008 OR alm_id:TCS00009 OR alm_id:TCS00010 OR alm_id:TCS00011 OR alm_id:TCS00012 OR alm_id:TCS00013 OR alm_id:TCS00020 OR alm_id:TCS00024 OR alm_id:TCS00032)
但我很困惑如何使用斜杠修改查询字符串 \和双引号 " .
我找不到规则,谢谢!

最佳答案

  • 斜线 - \\
  • 报价 - \"
  • System.out.println("\\ \"hello\"");
    输出:
    \ "hello"

    关于您的查询,似乎键和值都必须在引号之间 "key":"value"
    String lotId="2020_A_88";
    String type="apples";
    String queryPart = "\"lotId\":\""+lotId+"\" AND \"type\":\""+type+"\"";
    System.out.println(queryPart);
    "lotId":"2020_A_88" AND "type":"apples"
    String example = String.format("Slash-> %s , Quotes-> %s", "\\" ,"\"name\""); 
    System.out.println(example);
    Slash-> \ , Quotes-> "name"
    String s = "\\";
    String q = "\"name\"";
    System.out.println("Slash-> "+s+" , Quotes-> "+q);
    Slash-> \ , Quotes-> "name"

    关于java - 如何在JAVA中转义特殊字符Restful API查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65476057/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com