java 正则提取json_java使用正则表达式的方法从json格式的字符串中提取需要的字符串...

a493737c1d3de7f8033eb5088b5f0fd0.png

要解析的json字符串:

{

"ROOT": {

"HEADER": {

"ROUTING": {

"ROUTE_KEY": "",

"ROUTE_VALUE": ""

}

},

"BODY": {

"OUT_DATA": {

"TABLES": [{

"TABLENAME": "BS_FUNCTION_DICT",

"DATARECORDS": [{

"COLS": {

"FUNCTION_CODE": "2923",

"FUNCTION_NAME": "权限信息管理"

},

"OP": "I"

}]

}]

}

}

}

}

实现代码如下:

String content = " {\n" +

"\t\"ROOT\": {\n" +

"\t\t\"HEADER\": {\n" +

"\t\t\t\"ROUTING\": {\n" +

"\t\t\t\t\"ROUTE_KEY\": \"\",\n" +

"\t\t\t\t\"ROUTE_VALUE\": \"\"\n" +

"\t\t\t}\n" +

"\t\t},\n" +

"\t\t\"BODY\": {\n" +

"\t\t\t\"OUT_DATA\": {\n" +

"\t\t\t\t\"TABLES\": [{\n" +

"\t\t\t\t\t\"TABLENAME\": \"BS_FUNCTION_DICT\", \n" +

"\t\t\t\t\t\"DATARECORDS\": [{\n" +

"\t\t\t\t\t\t\"COLS\": {\n" +

"\t\t\t\t\t\t\t\"FUNCTION_CODE\": \"2923\",\n" +

"\t\t\t\t\t\t\t\"FUNCTION_NAME\": \"权限信息管理\" \n" +

"\t\t\t\t\t\t},\n" +

"\t\t\t\t\t\t\"OP\": \"I\" \n" +

"\t\t\t\t\t}]\n" +

"\t\t\t\t}]\n" +

"\t\t\t}\n" +

"\t\t}\n" +

"\t}\n" +

"}";

String regex = "\"TABLENAME\": \"(.*?)\",";

Matcher matcher = Pattern.compile(regex).matcher(content);

if (matcher.find()) {

String tableName = matcher.group(1);

System.out.println(tableName);

}

参考:

1.http://blog.csdn.net/yangruihong/article/details/17245359;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值