我想在下面的字符串中获取 id 字段的值,其中 inuse 字段的值为 1 。
"version": "IPv6",
"primarywins": null,
"id": 3,
"updated": 1368803376681,
"description": null,
"inuse": 0,
"alias": "Shared MGMT"
},
{
"computernameprefix": null,
"protocol": "static",
"version": "IPv4",
"primarywins": null,
"id": 5,
"updated": 1368912314856,
"description": null,
"inuse": 1
我正在尝试下面的java代码
String regex = "\"id\": ([0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9]),\n.*,\n.*,\n.*\"inuse\": 1";
Pattern index_pattern2 = Pattern.compile(regex,Pattern.DOTALL);
Matcher cMatcher2 = index_pattern2.matcher(The string mentioned above);
if(cMatcher2 != null && cMatcher2.find()
{
ipGrp = cMatcher2.group(1);
}
上面代码中 ipGrp 的值始终为 3,而我想将值设为 5 关于当 in use 的值为 1 时如何获取正确 id 字段的值的任何建议