java使⽤正则表达式的⽅法从json串⼉,取想要的value值例⼦1:
现有json:
({"code":"200","json":["111"],"message":"true"})
从中提取json的value数据。
直接上代码如下:天籁音乐>aggravated
分词作定语import java.util.ArrayList;
import Matcher;
import Pattern;
public class Snippet {
turbinespublic static void main(String[] args) {树袋熊英文
ArrayList json = new ArrayList();
json.add("111");
Ur ur = new Ur();
ur.tJson(json);
ur.tCode("200");
ur.tMessage("true");
String string = "(" + JSONString(ur) + ")";
// String regex = "\"json\":(.*?),\"message\"";// 使⽤⾮贪婪模式!
Pattern pattern = pile("\\[\"(.*?)\"\\]");
Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.up(1));
}
}
flanker
}
例⼦2:
leatherString str = "我是[001]真⼼求救的[002],你能帮帮我吗";
Pattern pattern = pile("\\[(.*?)\\]");
Matcher matcher = pattern.matcher(str);
while(matcher.find()){
System.out.up(1));
}
例⼦3:
public static void main(String[] args) {
String
par="[{CSTM_NO:\"11118\",CSTM_NAME:\"⼴东XX电⼒有限公司\",FIX_GNL:\"111810158\",FIX_ACC:\"D201306070003\",OP_FLAG:\"正常\",BUSS_KIND_NAME:\"三个⽉定期存款\",BAL:\"25,178,750.00\",AVAL_BAL:\"25,178,750.00\",OP_DATE:\"2013-06-07\",DUE_DATE:\"2013-12-07\",ROWNUM_:1,idx:0},{CSTM_NO:\"11118\",CSTM_NAME:\"⼴东XX电⼒有限公司
\",FIX_GNL:\"111810158\",FIX_ACC:\"D201306070002\",OP_FLAG:\"正常\",BUSS_KIND_NAME:\"三个⽉定期存款
\",BAL:\"25,178,750.00\",AVAL_BAL:\"25,178,750.00\",OP_DATE:\"2013-06-07\",DUE_DATE:\"2013-12-07\",ROWNUM_:3,idx:2},
{CSTM_NO:\"11118\",CSTM_NAME:\"⼴东XX电⼒有限公司\",FIX_GNL:\"111810158\",FIX_ACC:\"D201306070005\",OP_FLAG:\"正常
\",BUSS_KIND_NAME:\"三个⽉定期存款\",BAL:\"25,178,750.00\",AVAL_BAL:\"25,178,750.00\",OP_
DATE:\"2013-06-07\",DUE_DATE:\"2013-12-07\",ROWNUM_:4,idx:3}]";
String regex="FIX_ACC:(.*?),OP_FLAG";//别忘了使⽤⾮贪婪模式!
Matcher pile(regex).matcher(par);
while(matcher.find())
{
String up(1);
System.out.println(ret);divas
洗脸后护肤步骤
}海洋之心英文
}
总结:(.*?)这个拿出来,左边括号左边是左边界,右边括号右边是右边界,选对后直接匹配,即可拿到