json字符串如下:
{"page_size":0,"page_index":0,"page_count":0,"has_next":false,"datas":null,"code":0,"issuccess":true,"msg":null}
解析如下:
String regex="\"code\":(.*?),\"issuccess\"";//使用非贪婪模式
Matcher matcher=Pattern.compile(regex).matcher(jsonString);
while(matcher.find())
{
String ret=matcher.group(1);
if("0".equals(ret)){
json2dto = new ObjectMapper().readValue(jsonString, JstOrdersOutQueryDTO.class);
}else{
throw new Exception("没有成功得到json信息,请检查!!");
}
}
总结:
(.*?)这个拿出来,左边括号左边是左边界,右边括号右边是右边界,选对后直接匹配,即可拿到