• java把类似a=1&b=2&c=3的String类型数据转成map集合


     1 public static Map<String, Object> transStringToMap(String mapString, String separator, String pairSeparator) {
     2         Map<String, Object> map = new HashMap<String, Object>();
     3         String[] fSplit = mapString.split(separator);
     4         for (int i = 0; i < fSplit.length; i++) {
     5             if (fSplit[i]==null||fSplit[i].length()==0) {
     6                 continue;
     7             }
     8             String[] sSplit = fSplit[i].split(pairSeparator);
     9             String value = fSplit[i].substring(fSplit[i].indexOf('=') + 1, fSplit[i].length());
    10             map.put(sSplit[0], value);
    11         }
    12 
    13         return map;
    14     }

    //把String类型的字符串转成map集合,再遍历出来
    public
    static void main(String[] args) { String str = "RespCode=F0000&Plain=RespCode=F0000~~RespMsg=成功~~TradeResult=0&Signature=05bd95572c29726e6ff2f2b8f4879889948af05da9c656a8e3b799a8097bd260158e823e4e3a8dcf723189c09816ede5f82d8681abbf18bb8bab023949f766df004e09385b7c62fdb792385d45dbbf4bc7b77b1f9552af3dc023d362742e009207e3ef5e33e57f66dce1d10e28a3a55ad9bde1c7d25f6fa96a8a0449"; Map<String, Object> map = StringUtil.transStringToMap(str, "&", "="); for (String key : map.keySet()) { System.out.println("key:" + key + ", value:" + map.get(key)); } }



  • 相关阅读:
    [梦]2005.2.10
    日语广播总汇
    数词与量词
    切忌望文生义的日文汉字
    特別な読み方の漢字
    日本语能力考简介
    一天三练
    兴趣记忆法(1)顺口溜记忆
    兴趣记忆(3)谚语
    兴趣记忆(2)学歌
  • 原文地址:https://www.cnblogs.com/zyf-yxm/p/9020672.html
Copyright © 2020-2023  润新知