Parsing query strings on Android

前端 未结 25 1399
时光说笑
时光说笑 2020-11-22 17:41

Java EE has ServletRequest.getParameterValues().

On non-EE platforms, URL.getQuery() simply returns a string.

What\'s the normal way to properly parse the qu

25条回答
  •  猫巷女王i
    2020-11-22 17:42

    this method takes the uri and return map of par name and par value

      public static Map getQueryMap(String uri) {
    
        String queryParms[] = uri.split("\\?");
    
        Map map = new HashMap<>();// 
    
        if (queryParms == null || queryParms.length == 0) return map;
    
        String[] params = queryParms[1].split("&");
        for (String param : params) {
            String name = param.split("=")[0];
            String value = param.split("=")[1];
            map.put(name, value);
        }
        return map;
    }
    

提交回复
热议问题