jsonToGet把json格式接口传参转换为get请求

package com.xx.logPlayBack.xx.utils;

public class jsonToGet {

    public static void main(String[] args) {

        // 从数据库读取的日志如下,测试Demo""转义为''
        
        String strJson = "{'appScene':'new','systemInfo':'{'version':'8.4.2','type':'2,3,5,7'}}";
        // { }分别转义为空   " '分别转义为空   :转义为=   ,转义为&
        String strGet = strJson.replace("{", "").replace("}", "").
                replace("\"", "").replace("'", "").
                replace(":", "=").replace(",", "&");
        System.out.println("======转义前的strJson请求为======" + strJson);
        System.out.println("======转义后的strGet请求为======" + strGet);



        String jsonRequest = "{\"appScene\":\"mobile_multi\",\"system_info\":\"{\\\"ver\\\":\\\"8.5.2\\\",\\\"os\\\":\\\"Android\\\"}";
        String getRequest = jsonRequest.replace("{", "").replace("}", "").
                replace("\"", "").replace("'", "").
                replace(":", "=").replace(",", "&");

        System.out.println("======转义前的jsonRequest请求为======" + jsonRequest);
        System.out.println("======转义后的getRequest请求为======" + getRequest);

    }

}

运行结果:

待续。。。

发布了65 篇原创文章 · 获赞 13 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_42498050/article/details/105020554