Java截取字符串双引号里的字符输出
public static void main(String[] args) {
String str = "{\"product\":\"1\",\"code\":\"5772\",\"param\":\"200\"}";
Pattern p1= Pattern.compile("\"(.*?)\"");
Matcher m = p1.matcher(str);
List<String> params = new ArrayList<>();
while (m.find()) {
System.out.println((m.group().trim().replace("\"","")));
params.add((m.group().trim().replace("\"","")));
}
Map map = new HashMap();
for (int i = 0; i < params.size()/2; i++){
map.put(params.get(2*i),params.get(2*i+1));
}
System.out.println(map);
}
输出结果
product
1
code
5772
param
200
{product=1, code=5772, param=200}