zoukankan      html  css  js  c++  java
  • String 和 json 的常用方法

    去除字符串中的汉字:
    String str = "YYY54123上海市";
    String reg = "[u4e00-u9fa5]";
    Pattern pat = Pattern.compile(reg);
    Matcher mat=pat.matcher(str);
    String repickStr = mat.replaceAll("");
    System.out.println(repickStr);

    取出字符串中的汉字:
    String str = "Raaaaa怎取出来0.0111-0.1532";
    String reg = "[^u4e00-u9fa5]";
    str = str.replaceAll(reg, " ").trim();
    System.out.println(str);


    字符串中的,换成、
    String number = "长阳路,江浦路";
    String newNumber = number.replace(",", "、");
    System.out.println(newNumber);

    //去掉字符串头尾:
    String oleStr = "testldld";
    String newStr = oleStr.substring(1, oleStr.length()-1);
    System.out.printf("11111:"+ " "+newStr);

    //json 拼接
    String d="{"username1":"zhangsan","password1":"zhangsan"}";
    net.sf.json.JSONObject json1= net.sf.json.JSONObject.fromObject(d);
    String e="{"username2":"lisi","password2":"lisi"}";
    net.sf.json.JSONObject json2=net.sf.json.JSONObject.fromObject(e);
    net.sf.json.JSONObject json = new net.sf.json.JSONObject();
    json6.putAll(json1);
    json6.putAll(json2);
    System.out.println(json);


    取json字符串 中的jsonArray

    JSONArray data = saveJson.getJSONArray("data");//数组名
    saveJson=data.getJSONObject(0);//第一个json
    String applyNo = saveJson.getString("applyNo");//取出参数

  • 相关阅读:
    PostgreSQL pg_hba.conf 文件简析
    Centos 查看端口占用情况
    Nginx 从0开始学
    windows 杀死端口号对应进程
    MyBatis基础-05-缓存
    MyBatis基础-04-动态sql
    MyBatis基础-02
    SpringMVC基础-14-SpringMVC与Spring整合
    SpringMVC基础-13-SpringMVC运行流程
    SpringMVC基础-12-异常处理
  • 原文地址:https://www.cnblogs.com/lifan12589/p/11711973.html
Copyright © 2011-2022 走看看