java使⽤正则表达式的⽅法从json串⼉,取想要的value值例⼦1:
现有json:
({"code":"200","json":["111"],"message":"true"})
从中提取json的value数据。
直接上代码如下:
import java.util.ArrayList;
import Matcher;
import Pattern;
public class Snippet {
public 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));
}
}
}
例⼦2:
String 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);仓库管理技巧
}
}
总结:(.*?)这个拿出来,左边括号左边是左边界,右边括号右边是右边界,选对后直接匹配,即可拿到