我后台有这么一个字符串 [{"types":"收入","id":6},{"totalmoney":123,"id":7},{"types":"支出","id":8}]
我想通过正则表达式来分别得出“{}”内的一个对象
如String s="{'types':'收入','id':6}";这种形式,请问怎么弄,谢谢
[code="java"] public static void main(String[] args) {
String source = "[{\"types\":\"收入\",\"id\":6},{\"totalmoney\":123,\"id\":7},{\"types\":\"支出\",\"id\":8}]";
String regex = "(\\{.*?\\})";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(source);
while(matcher.find()){
System.out.println(matcher.group(1));
}
}[/code]