怎么从json字符串中截取字符串
2016-07-10 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
这样的话,只需要截取需要的字符串即可。
举例:
public static void main(String[] args) {
String parse="[{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 matcher=Pattern.compile(regex).matcher(parse);
while(matcher.find())
{
String ret=matcher.group(1);
System.out.println(ret);
}
}
举例:
public static void main(String[] args) {
String parse="[{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 matcher=Pattern.compile(regex).matcher(parse);
while(matcher.find())
{
String ret=matcher.group(1);
System.out.println(ret);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询