Forum Discussion
Hi SK07,
I believe you should can get solution from scripts which I replied to you in your previous topic, right?
firstly, you should parse json string as a json object, right? you should do this at first step.
secondly, retrieve 'Ids' and get content. (if "Ids" 's value is always like []. if not, you can add a 'if' condition to determine, like: if(a instanceof ArrayList), a means Ids' value)
thirdly, you also get all values of Ids, so you can count the numer of them.
If any enquires, please post your questions here
Regards,
/Aaron
- SK077 years agoContributor
Hi Aaron, This is something different from previous with inner loops.
Json : {"prods": [{"Item":13,"rate":200, "Ids": []},
{"Item":14,"rate":300, "Ids": []},
{"Item":15,"rate":100, "Ids": [ {"level": 1}]},
{"Item":16,"rate":700, "Ids": [ {"level": 1}]},
{"Item":17,"rate":500, "Ids": [ {"level": 2} ], [{"level": 2}, {"level": 2}]} ]}.So, I retrieve the Ids as below:
def jsonids = json.Ids
log.info jsonids
[[], [], [1], [1], [2, 2, 2]]But I dont how to read/count the above and get the results like below:
Ids [] =: 2, Level 1 = 2, Level 2 = 3
- aaronpliu7 years agoFrequent Contributor
Hi SK07,
Dont think of it to be complex. If you only wanna count the number of "[]", try
// your list aa=[[], [], [1,1],[2,2,2]] def num = 0 for(item in aa){ if(item.size() < 1) num++ } log.info "[Ids []: $num]"
Regards,
/Aaron
- SK077 years agoContributor
Thank you! Aaron.
Related Content
- 6 years ago
- 7 years ago
- 3 years ago
Recent Discussions
- 5 days ago
- 10 days ago