In my below code, colData stores JSON String. Sample example for colData-
{"lv":[{"v":{"tenureSiteReg":null,"bghtItms":48,"pnlValue":105.478409,"byrSgmnt":2,"cstmrId":"814296998","slrRevRnk":-99.0,"soldItms":0,"slrSgmnt":6,"byrRevRnk":0.013,"mainAcct":78,"gmv":0.0,"cstmrRevRnk":0.021,"pnlRev":313.438843,"cstmrSgmnt":51,"gmb":4674.76,"totalVal":142.536293,"userId":493},"cn":42}],"lmd":20130}
Now I am trying to match id value with userId value in the above JSON String.
Meaning if id value is 493 then in the above JSON String userId value should also be 493. And in the JSON String, it might be possible there are lot of userId values so all the userId values should be matching with id. If any of them doesn't matches then log the exception.
So I was trying something like this-
private static final Pattern USER_ID_PATTERN = Pattern.compile("userId:\\d+");
for (String str : colData) {
Matcher matcher = USER_ID_PATTERN.matcher(str);
while (matcher.find()) {
if (!matcher.group().equals("userId:"+id))
System.out.println("LOG exception");
}
}
But for the above JSON String, it is not going inside while loop also. Is there anything I am missing?
idvalue come from? Is it a separate string or is it supposed to be in the JSON?