java字符串取值
黄舟
黄舟 2017-04-17 17:11:34
0
4
440
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(4)
迷茫
    String dataStr="[id=1,mid=2]";
    dataStr="{"+dataStr.replaceAll("=", ":").substring(1,dataStr.length()-1)+"}";
    JSONObject data=JSONObject.parseObject(dataStr);
    System.out.println(data.get("id")+","+data.get("mid"));

You can use tools, such as Alibaba's fastjson, to first format the string into json format (intercept and split it), and then get the value through the key

Ty80

1. The string in java should be defined this way: String stats="[id=1,mid=2]";
2. What value do you want to take? The description is not clear

洪涛

The non-standard method is to use "," to split the string, and then use "=" to split it. The first part is the key and the last part is the value. Then you can store it as a map or other methods.

伊谢尔伦
    String[]str = new String[]{"id=1","mid=2"};
    String array = Arrays.toString(str); // 获取你这样的字符串
    String mapString = array.replace("[", "{").replace("]", "}");
    Map<String, Integer> map = new Gson().fromJson(mapString, new TypeToken<Map<String, Integer>>() {
    }.getType());
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!