I have a JSON String as-
[{"lv":[{"v":{"nt":"10;1341943000000","userId":622},"cn":0},
{"v":{"nt":"20;1234567890123","userId":622},"cn":0},
]
In this JSON String I will be having userId as the property for each values. It might be possible that in a Single JSON String I am having 10 userId property or 15 userId property. And userId will have some number always.
Each JSON String will have same number in userId. If you see the above JSON String, I have 622 as the number for each userId.
Now I am trying to compare id with userId in the JSON String. I am getting id value from some other means, like this-
final int id = generateRandomId(random);
So id value should be matching with all the userId property in a single JSON String.
And I am storing all the JSON String in colData List<String>. And currently I am trying to match id with userId using contains method of String class, which I believe is not correct because as soon as it finds one match then if conditions will get true (Which is wrong).
It might be possible that in a Single JSON String 20 userId properties are there and 19 userId values are matching with id but one userId property value is not same. So that use case will get failed in my below code. So how can I achieve this problem definition
for (String str : colData) {
if (!str.contains(String.valueOf(id))) {
// log the exception here
handleException(ReadConstants.ID_MISMATCH, Read.flagTerminate);
}
}
Thanks for the help.