I’m testing an API and get all data from the DB. I save the response as
MvcResult result = mockMvc.perform(..some code..).andReturn();
I get a json as response. I want to get the length of json array. So, if I have 2 rows in DB, I want to get 2 as a result.
Or is there maybe another way to count number of rows which are present in the DB.
Advertisement
Answer
if you want to get json array length this is the way,
1.if you import org.json.simple.JSONArray
you can use JSONArray.size()
2.if you import org.json.JSONArray
you can use JSONArray.length()